Click here to Skip to main content
15,749,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am having an issue, when a method(AdminList) is called from AdminController the correct code path is followed(*2) but thereafter it loads the _Layout(*1) which has a Partial View(*3) with a different Model(LoginModel). I get the following error -> "The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Ts.Global.Models.AdminModel]', but this dictionary requires a model item of type 'Ts.Global.Models.TsAccount.LoginModel'."

Any assistance would be highly appreciated.

1. _Layout.cshtml is as follows
    @Html.Partial("Sections/_Header") @*Model: LoginModel*@

2. AdminController/AdminList
return View(adminModel);

3. AccountController/Login
return PartialView(webLoginModel);

4. Login.cshtml - Partial View
@using Ts.Global.Helpers;
@model Ts.Global.Models.TsAccount.LoginModel
<div id="mHeader" class="mHeader"> 

5. AdminList.cshtml
@model List<Ts.Global.Models.AdminModel>
        <td>Select Administrator</td>
Updated 8-Oct-15 1:18am

1 solution

Error is pretty clear, View requires the AdminModel & You're passing the LoginModel.

What you can do is, combine those two models in one and pass that one model only to the view.
For example,
public class UserViewModel
    public AdminModel adminModel;
    public LoginMode loginModel;

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900