How do I return a View and a Partial View to the Index Layout in ASP.NET MVC 4? c# entity-framework-6 partial-views razor


My "StatusController" and my "Home Controller" both produce a fresh instance of a DBEntities. The Status Controller returns a _db.Jobs ViewDataModel to the _GetForStatus.cshtml view as a partial view, while the Home Controller returns a _db.VMs ViewData.Model to the _Layout.cshtml view. The following is how I call the VMs ViewData model to the _Layout view:

 @foreach (var m in ViewData.Model)
           <li><a href="#">@m.Name</a></li>

This procedure successfully adds the names of the VMs from the DB to the drop-down list. using the _GetforStatus. This is how the Home Controller piece is written:

 public ActionResult index()
           _db = new IntegrationDBEntitires();
           ViewData.Model = _db.VMs.ToList();
           return View();

The StatusController is expressed as follows:

 public PartialViewResult _GetforStatus()
           _db = new OntegrationDBEntities();
           ViewData.Model = _db.Jobs.ToList();
           return PartialView();

This is how the _GetforStatus view is written:

 @model IntegrationWeb.Models.Job
      <div class="progress progress-striped active">
           <div class="progress-bar" style="width: @((Model.IS_Progress / Model.IS_Total)*100)%"></div>
 @Html.Action("_GetforStatus", "StatusController")

This is referred to as such in the _Layout view:


Here, I'm getting a mistake. " The dictionary accepts a model item of type 'System.Collections.Generic.List' 1[IntegrationWeb.models.VM]' but prefers IntegrationWeb.Models.Job as the model item type. Pulling two separate DBEntities into the Layout view appears to cause a disagreement.
In ASP.NET MVC 4, how do I send a View and a Partial View back to the Index Layout?

Since I'm unable to figure out why it won't recognize my Controller, "StatusController," I've just added the Action to the Home Controller. Now when I use @Html.RenderAction(" GetforStatus"); I get a different problem. "This dictionary requires a model item of type 'IntegrationWeb.models.Job', but the model item supplied into the dictionary is of type 'System.Collections.Generic.List '1[IntegrationWeb.models.Job]'." Does anyone have any idea what's going on?

2/17/2015 6:40:20 PM

Accepted Answer

2/17/2015 4:07:29 PM

Popular Answer

in place of


just act

@Html.Action("_GetForStatus", "MyController")

Html.Partial renders the cshtml file but does not execute the action.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow