Click here to Skip to main content
15,399,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I may just tired, frustrated and grabbing at straws but here goes.

I tried using Areas in my MVC Web app and was running into issues with resolving paths so I moved my admin page back in to the main area.

When I did the Admin controller gets called which in turn invokes the Admin/Index page which loads in a partial page and it all gets filled with a list of List<commentviewmodel> information that I send it but when it's done servicing the list, and I don't know at what point this happens I get an exception saying that the page is looking for a list List<userviewmode> of information that's required in my Home/Index page??

Layout.cshtml - Admin page is the one in question
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li>
    @if (User.IsInRole("Admin"))
    {
        @Html.ActionLink("Admin", "Index", "Admin")
    }
</li>


RouteConfig.cs
C#
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        namespaces: new string[] { "JaxCoderV20.Controllers" }
    );
}


AdminController.cs
XML
[HttpGet]
public ActionResult Index()
{
    List<CommentViewModel> list = UberService.GetAllCommentsExtended();

    return View(list);
}


and a portion of Index.cshtml
@using JaxCoderV20.ViewModels;
@Model IEnumerable<jaxcoder.viewmodels.commentviewmodel>

    @{
        ViewBag.Title = "Admin Main Page";
        ViewBag.Description = "Main entry point/page for Admin";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }

   .............. More suuff here ............

<div id="approval" class="tab-pane">
     <a href="DownloadHandler.ashx?fileid=922528934">Article Source (81KB)</a>
     @foreach (var item in Model)
     {
        Html.RenderPartial("_CommentView", (CommentViewModel)item);
     }
</div>


I'm new to MVC so I'll probably be posting a lot of questions here so if you spot that I'm doing something wrong pipe up and let me know so I don't flouder latter. Thanks y'all
Posted
Comments
Mike Hankey 13-Feb-15 6:18am
   
BTW the error is

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

1 solution

It turns out I had used the UserViewModel on the _Layout page to fill in some user information and it appears that the _layout view model trumps all other down the chain. Which I guess makes sense but once I changed it everything fell into place.
   

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



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