Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

MVC with entity framework using different data models on layout page and views

$
0
0

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>();
            StateWithPropertiesList=Obj.GetStatesWithProperties(0,false,"State","Up");
            //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.


Viewing all articles
Browse latest Browse all 5347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>