ASP.Net MVC Error: The model item passed into the dictionary is of type System.Collections.Generic.List1

Last Reply on Aug 13, 2018 05:59 AM By dharmendr

Posted on Aug 13, 2018 02:28 AM

Error in MVC:The model item passed into the dictionary is of type System.Collections.Generic.List1

              var detail = (from p in db.Partner_Details
                          join h in db.Height_Table on p.Height_min equals h.Height_Id
                          join h1 in db.Height_Table on p.Height_max equals h1.Height_Id
                          join r in db.Religions on p.Religion equals r.Religion_Id
                          join c in db.Castes on p.Caste equals c.Caste_Id
                          join m in db.Marital_Status on p.Marital_Status equals m.Status_Id
                          join mt in db.Mother_Tongue on p.Mother_Tongue equals mt.Language_id
                          join ct in db.Country_Name on p.Country_of_Resident equals ct.Country_Id
                          join st in db.State_Name on p.State_of_Resident equals st.State_Id
                          join e in db.Education_Qualification on p.Education_Qualification equals e.Education_Id
                          join anlincm in db.AnnuaIncome_Table on p.Annual_Income equals anlincm.Income_Id
                          join mn in db.Manglik_Table on p.Manglik equals mn.Manglik_Id
                          join sc in db.SpecialCase_Table on p.Special_Cases equals sc.SpecialCase_Id
                          join d in db.Diet_Table on p.Diet equals d.Diet_Id

                          select new partnerDetails
                          {
                              Age_from = p.Age_from,
                              Age_to = p.Age_to,
                              Height_Min = h.Height,
                              Height_Max = h1.Height,
                              Relegions = r.Religion_Name,
                              Castes = c.Caste1,
                              Marital_status = m.Status,
                              Mother_tongue = mt.Language,
                              Country_of_resident = ct.Country,
                              State_of_resident = st.State,
                              Education_qualification = e.Education,
                              Annual_income = anlincm.Annual_Income,
                              Mangliks = mn.Manglik,
                              Special_cases = sc.Special_Case,
                              Diets = d.Diet
                          }
                        ).ToList();
            return View(detail.ToList());

 

@model  Wedding_Plan.Wedding_Repository.partnerDetails

@{
    ViewBag.Title = "Partner_Details";
    Layout = "~/Views/Shared/_Layout_Inner.cshtml";
}

<h2>Partner_Details</h2>

<div>
    <h4>users_details</h4>
    <hr />
    <dl class="dl-horizontal">

        <dd>
            @Html.DisplayFor(model => model.Age_from)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Age_from)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.Age_to)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Age_to)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.Height_Min)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Height_Min)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.Height_Max)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Height_Max)
        </dt>
 </dl>
</div>

 

Posted on Aug 13, 2018 03:39 AM

Hi mukesh1,

Your Controller ActionResult returns List but View doesn't declared as IEnumerable.

So either do one of the change.

  • Return single result from ActionResult.
  • Or declare the partnerDetails class as IEnumerable in the view and bind the result using loop.

Posted on Aug 13, 2018 05:59 AM
mukesh1 says:
@model  Wedding_Plan.Wedding_Repository.partnerDetails

 Change the above with below.

@model IEnumerable<Wedding_Plan.Wedding_Repository.partnerDetails>

Then use for each loop to bind the result. Refer below link.

Edit and Update record in HTML Table using Entity Framework in ASP.Net MVC