none
Model item passed into the dictionary

    Question

  • Hi all....

    While Ruunning My First Asp.Net MVC Application I am Getting Following error:

    The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[ContactManagementSystem.Models.EmployeeMaster]', but this dictionary requires a model item of type 'ContactManagementSystem.Models.ViewData.IndexModel'.

    from Index.aspx View ,

    following is the code of Index.aspx

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ContactManagementSystem.Models.ViewData.IndexModel>" %>

    <%@ Import Namespace="Helpers" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent"  runat="server">

    <title>Index</title>

    </asp:Content>

     

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

     

    <ul id="leftColumn">

    <% foreach (var item in Model.Group_Master ) { %>

       <li <%= Html.Selected(item.Code, Model.SelectedGroup.Code) %>>

      <%= Ajax.ActionLink(item.Name, "Index", new { id = item.Code }, new AjaxOptions { UpdateTargetId = "divContactList" })%>

        </li>

    <% } %>

    </ul>

    <div id="divContactList">

       <% Html.RenderPartial("ContactList", Model.SelectedGroup ); %>

    </div>

     

    <div class="divContactList-bottom"> </div>

    </asp:Content>

     

     

    Can Any One Help ....

    Thanks...

    Friday, September 03, 2010 9:33 AM

Answers

  • Hi,

    I believe you confuse your ViewModel with your Business Entities. Your ViewModel contains all the values your View wants to work with. It can be comprised of multiple flattened Business Entities. If you need two ViewModels in one ViewPage, you know you're doing something wrong ;).

    So, to answer your question, I think you should re-evaluate your ViewModels and merge them into one or you could consider adding a ViewPage and thus creating an extra step (like a wizard) in your user user experience.


    If this reply is of help to you, please don't forget to mark it as an answer. Regards, Patriek
    • Marked as answer by Nancy Shao Wednesday, September 08, 2010 10:22 AM
    Friday, September 03, 2010 2:54 PM

All replies

  • Hi,

    I think the error message speaks for it's self. Your ViewPage is a typed ViewPage for the type IndexModel. You should pass an object of type IndexModel when you return the ActionResult in your Controller action.

    It seems that you return a model of type EmployeeMaster.

    Perhaps you could post the controller action after which this exception is thrown.


    If this reply is of help to you, please don't forget to mark it as an answer. Regards, Patriek
    Friday, September 03, 2010 11:24 AM
  • Hi,

    Then Please tell Me what i can do here because i want to Acess both

    <% foreach (var item in Model.Group_Master ) { %>

       <li <%= Html.Selected(item.Code, Model.SelectedGroup.Code) %>> 

    and 

    <%--<% foreach (var item in Model.SelectedGroup.Employee_Master )

               { %>--%>

    in index.aspx

    here

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ContactManagementSystem.Models.ViewData.IndexModel>" %>

    is used for this purpose where 

    ViewData is partial here

    using System.Collections.Generic;

    namespace ContactManagementSystem.Models.ViewData

     

    {

        public class IndexModel

        {

            public Group SelectedGroup { get; set; }

            public IEnumerable<Group> Group_Master { get; set; }     

        }

    }

     

    Thanks


    Friday, September 03, 2010 11:50 AM
  • Hi,

    I believe you confuse your ViewModel with your Business Entities. Your ViewModel contains all the values your View wants to work with. It can be comprised of multiple flattened Business Entities. If you need two ViewModels in one ViewPage, you know you're doing something wrong ;).

    So, to answer your question, I think you should re-evaluate your ViewModels and merge them into one or you could consider adding a ViewPage and thus creating an extra step (like a wizard) in your user user experience.


    If this reply is of help to you, please don't forget to mark it as an answer. Regards, Patriek
    • Marked as answer by Nancy Shao Wednesday, September 08, 2010 10:22 AM
    Friday, September 03, 2010 2:54 PM
  • Thanks for You Help Patriek :)
    Saturday, September 04, 2010 4:34 AM