如何将多个模型传递给控制器并将数据绑定到视图
我在该页面中有列表页面包含两个选项卡,一个用于活动列表,另一个用于活动列表。
如何创建模型并将数据绑定到viewpage。
如何将数据绑定到视图页面,我使用强类型模型
public class MyViewModel
{
public IEnumerable<SomeViewModel> Active { get; set; }
public IEnumerable<SomeViewModel> InActive { get; set; }
}
这是我的观看页面代码
<% foreach (var model in Model)
{ %>
<tr>
<td>
<%= Html.ActionLink(model.TITLE, "Detail", new { id = model.EVENT_ID })%>
</td>
我收到了错误
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'System.Collections.Generic.IEnumerable<EventListing.Models.MyViewModel>' does not contain a definition for 'Active' and no extension method 'Active' accepting a first argument of type 'System.Collections.Generic.IEnumerable<EventListing.Models.MyViewModel>' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 221: </thead>
Line 222: <tbody>
Line 223: <% foreach (var model in Model.Active)
Line 224: { %>
Line 225: <tr>
答案 0 :(得分:3)
您可以将包含两个列表的视图模型作为属性:
public class MyViewModel
{
public IEnumerable<SomeViewModel> Active { get; set; }
public IEnumerable<SomeViewModel> InActive { get; set; }
}
然后将MyViewModel
的实例传递给控制器操作的视图。