The model item passed into the dictionary is of type 'System.Net.Http.HttpResponseMessage',

İsmail Hakkı Şen

Full error

The model item passed into the dictionary is of type 'System.Net.Http.HttpResponseMessage', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`

I'm trying to get some data from web api with viewmodel.

This is my action

public ActionResult PayBilgileri()
    {
        Session["dersGrupID"] = 470122;
        int DersGrupID = Convert.ToInt32(Session["dersGrupID"]);

        Core.ViewModel.Ders.DersDetay.PayVeNotBilgileriViewModel PayBilgileri = new Core.ViewModel.Ders.DersDetay.PayVeNotBilgileriViewModel();

        PayBilgileri.DersPlanID = DersGrupID;

        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri("http://myapi.com");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //HttpResponseMessage response = client.GetAsync("api/Ders/ListelePaylarVeNotBilgileri").Result;
            var response = client.PostAsJsonAsync("api/Ders/ListelePaylarVeNotBilgileri", PayBilgileri).Result;
            if (response.IsSuccessStatusCode)
            {

            }
            return PartialView(response);
            // PartialViewResult(response, JsonRequestBehavior.AllowGet);
        }

    }

And the partial view

@model IEnumerable<Core.ViewModel.Ders.DersDetay.PayVeNotBilgileriViewModel>

<table class="table">

@foreach (var item in Model) 
{
   <tr>
      <td>
          @Html.DisplayFor(modelItem => item.KatkiOrani)
      </td>
   </tr>
}
</table>
haim770

You need to extract the data from the HttpResponseMessage as IEnumerable<PayVeNotBilgileriViewModel> and only then pass it as the view-model:

if (response.IsSuccessStatusCode)
{
    var vm = response.Content.ReadAsAsync<IEnumerable<PayVeNotBilgileriViewModel>>().Result;
    return PartialView(vm);
}

See ReadAsAsync

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

The model item passed into the dictionary is of type 'System.Collections.Generic.List... in ASP.net MVC

From Dev

ASP.Net MVC "The model item passed into the dictionary is of type 'System.Collections.Generic.List"

From Dev

model item passed into the dictionary is of type 'System.Collections.Generic.List, but this dictionary requires a model item of type

From Dev

model item passed into the dictionary is of type 'System.Boolean', but this dictionary requires a model item of type 'MyProject.checkboxstate'

From Dev

The model item passed into the dictionary is of type 'System.Linq.Enumerable

From Dev

The model item passed into the dictionary is of type 'System.Data.Entity.DbSet

From Dev

MVC: The model item passed into the dictionary is of type System.Int32

From Dev

The model item passed into the dictionary is of type ..., but this dictionary requires ...

From Java

The model item passed into the dictionary is of type .. but this dictionary requires a model item of type

From Dev

The model item passed into the dictionary is of type ' ', but this dictionary requires a model item of type ' '

From Dev

The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

From Dev

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[X]', but this dictionary requires a model item of type 'X'

From Dev

The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

From Dev

The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'IMS.Models.Dealer'

From Dev

The model item passed into the dictionary is of type error

From Dev

ASP.NET MVC 5 The model item passed into the dictionary is of type 'Name.Models.IndexViewModel', but this dictionary requires a model item of type

From Dev

The model item passed into the dictionary is of type 'System.Threading.Tasks.Task`1[System.Collections.Generic.IEnumerable`

From Dev

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List`

From Dev

The model passed into dictionary is type 'TestApp.Models.Registration.RegistrationVm' but this dictionary requires a model item of type System.String

From Dev

The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery

From Dev

The model item passed into the dictionary is of type 'System.Collections.Generic.List in Razor mvc5

From Dev

"The model item passed into the dictionary is of type" while passing model to a partial view

From Dev

The model item passed into the dictionary is of type view model but requires generic IEnum

From Dev

"The model item passed into the dictionary is of type" while passing model to a partial view

From Dev

The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'TestModel'

From Dev

The model item passed into the dictionary is of type 'BlogHomePageModel', but this dictionary requires a model item of type 'BlogHomePageModel'

From Dev

The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'X'

From Dev

The model item passed into the dictionary is of type 'a', but this dictionary requires a model item of type 'b'

From Dev

How to fix The model item passed into the dictionary is of type error?

Related Related

  1. 1

    The model item passed into the dictionary is of type 'System.Collections.Generic.List... in ASP.net MVC

  2. 2

    ASP.Net MVC "The model item passed into the dictionary is of type 'System.Collections.Generic.List"

  3. 3

    model item passed into the dictionary is of type 'System.Collections.Generic.List, but this dictionary requires a model item of type

  4. 4

    model item passed into the dictionary is of type 'System.Boolean', but this dictionary requires a model item of type 'MyProject.checkboxstate'

  5. 5

    The model item passed into the dictionary is of type 'System.Linq.Enumerable

  6. 6

    The model item passed into the dictionary is of type 'System.Data.Entity.DbSet

  7. 7

    MVC: The model item passed into the dictionary is of type System.Int32

  8. 8

    The model item passed into the dictionary is of type ..., but this dictionary requires ...

  9. 9

    The model item passed into the dictionary is of type .. but this dictionary requires a model item of type

  10. 10

    The model item passed into the dictionary is of type ' ', but this dictionary requires a model item of type ' '

  11. 11

    The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

  12. 12

    The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[X]', but this dictionary requires a model item of type 'X'

  13. 13

    The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

  14. 14

    The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'IMS.Models.Dealer'

  15. 15

    The model item passed into the dictionary is of type error

  16. 16

    ASP.NET MVC 5 The model item passed into the dictionary is of type 'Name.Models.IndexViewModel', but this dictionary requires a model item of type

  17. 17

    The model item passed into the dictionary is of type 'System.Threading.Tasks.Task`1[System.Collections.Generic.IEnumerable`

  18. 18

    Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List`

  19. 19

    The model passed into dictionary is type 'TestApp.Models.Registration.RegistrationVm' but this dictionary requires a model item of type System.String

  20. 20

    The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery

  21. 21

    The model item passed into the dictionary is of type 'System.Collections.Generic.List in Razor mvc5

  22. 22

    "The model item passed into the dictionary is of type" while passing model to a partial view

  23. 23

    The model item passed into the dictionary is of type view model but requires generic IEnum

  24. 24

    "The model item passed into the dictionary is of type" while passing model to a partial view

  25. 25

    The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'TestModel'

  26. 26

    The model item passed into the dictionary is of type 'BlogHomePageModel', but this dictionary requires a model item of type 'BlogHomePageModel'

  27. 27

    The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'X'

  28. 28

    The model item passed into the dictionary is of type 'a', but this dictionary requires a model item of type 'b'

  29. 29

    How to fix The model item passed into the dictionary is of type error?

HotTag

Archive