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

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
<body>
    @Html.Partial("Sections/_Header") @*Model: LoginModel*@
    @RenderBody()    
    @Html.Partial("Sections/_Footer")
</body>

2. AdminController/AdminList
C#
return View(adminModel);

3. AccountController/Login
C#
return PartialView(webLoginModel);

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

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

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,
C#
public class UserViewModel
{
    public AdminModel adminModel;
    public LoginMode loginModel;
}


-KR
 
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