Can I not render a strongly typed partial in a strongly typed view?
I am getting the following error when I try to:
The model item passed into the dictionary is of type 'System.Data.Linq.Table
1[UI.Models.vwProject]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[UI.Models.ProjectStatus]'.
I populate both the views using ViewData.Model
public ActionResult Index()
{
ViewData.Model = project.vw_Projects;
return View();
}
public ActionResult ProjectStatus()
{
ViewData.Model = project.ProjectStatus;
return View();
}
Here is my View:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<UI.Models.vwProject>>" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div>
<table>
<tr>
<th>
Project
</th>
<th>
Hours
</th>
</tr>
<tr>
<td>
<%= Html.Encode(item.ProjectCode) %>
</td>
<td>
<%= Html.Encode(item.ProjectHours) %>
</td>
</tr>
<div>
<% Html.RenderPartial("ProjectStatus"); %>
</div>
</asp:Content>
Here is my partial:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<UI.Models.ProjectStatus>>" %>
<table>
<tr>
<th>
Code
</th>
<th>
Status
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%= Html.Encode(item.ProjectCode) %>
</td>
<td>
<%= Html.Encode(item.ProjectStatus) %>
</td>
</tr>
<% } %>
</table>
I am a little confused with how to display strongly typed/dynamic partials in strongly type or dynamic views. Can someone help me resolve this issue?
RenderPartial
? If you don't, it's getting the Model from the calling View. – TLS