Adding different models in view as well as in layout page RRS feed

  • Question

  • I am new to MVC.I am working on MVC with entity framework . I am using a function which returning List of objects .

    Adding below code on view.

     @model IEnumerable<WWM.DataModel.Helpers.StatesWithProperties>
        @{Layout = "~/Views/Shared/_Layout.cshtml";

    and my controller is like below

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using WWM.DataModel.Controllers;
    using WWM.DataModel.Helpers;

    namespace WWM.Website.Controllers
        public class AllListingsController : Controller
            // GET: AllListings
            public ActionResult Index()
                EntityController Obj = new EntityController();
           List<StatesWithProperties> StateWithPropertiesList=new List<StatesWithProperties>();
                //return View(StateWithPropertiesList);
                return PartialView(StateWithPropertiesList);

    but in layout page I have something like below.

    @model WWM.Website.Models.BaseViewModel

    and while running project getting below error

    The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[WWM.DataModel.Helpers.StatesWithProperties]', but this dictionary requires a model item of type 'WWM.Website.Models.BaseViewModel'.

    What is the proper solution of this.

    Tuesday, December 1, 2015 10:54 AM


  • They'll help you over here.





    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

    • Proposed as answer by Mike Laughlin Tuesday, December 1, 2015 2:42 PM
    • Marked as answer by Just Karl Tuesday, December 8, 2015 5:21 PM
    Tuesday, December 1, 2015 1:35 PM