I am trying to add a partial view to my MVC4 web application and I receive the following exception:
The model item passed into the dictionary is of type ‘…Meeting’, but this dictionary requires a model item of type ‘System.Collections.Generic.List`1[…UserProfile]’.
what I did so far:
- i added to my controller this function:
public PartialViewResult GetUsers() { var usersList = (from users in db.Users select users).ToList(); return PartialView(usersList); }
- I added the parital view:
@model List<UserProfile> @{ <select id="Meeting_SetToUser" name="Meeting.SetToUser"> @foreach (var item in Model) { <option value="@item.UserId">@item.FirstName @item.LastName</option> } </select> }
- i called the partialview from my view:
@Html.Partial("GetUsers")
can you please direct me to were I am doing anything wrong?
Thank you!
The
GetUsersaction doesn’t seem to ever be called when you useHtml.Partial. Maybe you wanted to use a child action:Checkout the
following articleto better understand the difference betweenHtml.PartialandHtml.Action.Also generating a dropdown list using a
foreachloop instead of using theHtml.DropDownListhelper seems quite inappropriate. Maybe you wanted to use this helper, didn’t you:I would also very strongly recommend you using view models instead of passing your domain models to the views.