I have an action that creates a List and returns it to my view..
public ActionResult GetCustomers()
{
return PartialView("~/Views/Shared/DisplayTemplates/Customers.cshtml", UserQueries.GetCustomers(SiteInfo.Current.Id));
}
And in the “~/Views/Shared/DisplayTemplates/Customers.cshtml” view I have the following:
@model IEnumerable<FishEye.Models.CustomerModel>
@Html.DisplayForModel("Customer")
Then I have in the “~/Views/Shared/DisplayTemplates/Customer.cshtml” view:
@model FishEye.Models.CustomerModel
@Model.Profile.FirstName
I am getting the error:
The model item passed into the dictionary is of type System.Collections.Generic.List`1[Models.CustomerModel]', but this dictionary requires a model item of type 'Models.CustomerModel'.
Shouldn’t it display the Customer.cshtml for every item in the collection in the Customers.cshtml?
Help!
I am not sure why you are calling a partial view like this. If it is a Customer Specific view, why not put it under
Views/Customerfolder ? Remember ASP.NET MVC is more of Conventions. so i would always stick with the conventions (unless abosultely necessary to configure myself) to keep it simple.To handle this situation, i would do it in this way,
a
CustomerandCustomerListmodel/VidemodelAnd in the action method, i would return an object of CustomerList class
Now there should be a view called
CustomerList.cshtmlunderViews/YourControllerName/folder. That view should look like thisHave a view called
Customer.cshtmlunderViews/Shared/DisplayTemplates with this contentThis will give you the desired output.