我是C#\ .NET的新手,我有以下疑问。
我正在处理这个Web应用程序的Jquery页面:
@model MyUsers.Models.SearchGroups
@{
ViewBag.Title = "Index";
Layout = "~/Areas/Admin/Views/Shared/MasterPageAdminMobile.cshtml";
WebGrid wGrid = new WebGrid(null, rowsPerPage: Model.PageSize, defaultSort: "NOME", canPage: false);
wGrid.Bind(Model.Gruppi, rowCount: Model.TotalRows, autoSortAndPage: false);
}
<h2>Gruppi</h2>
<a href="@Url.Action("Create", "Groups")" data-icon="plus" data-inline="true" data-mini="true" data-role="button" >Crea un nuovo gruppo</a>
@if (Model.TotalRows == 0)
{
<h3>Non è stato trovato nessun gruppo. Modificare i filtri di ricerca.</h3>
}
else
{
<div style="margin-top: 20px;">
@wGrid.GetHtml(
fillEmptyRows: false,
tableStyle: "MyTable ui-responsive",
headerStyle: "ui-bar-c",
footerStyle: "ui-bar-b",
rowStyle: "ui-bar-a",
alternatingRowStyle: "ui-bar-b",
htmlAttributes: new { data_role = "table", id = "MyWebGrid", data_mode = "reflow" },
columns: new[]{
wGrid.Column ("Nome","", canSort : true),
wGrid.Column ("countUsers","Numero utenti", canSort : false ),
wGrid.Column ("countRoles","Numero ruoli", canSort : false ),
wGrid.Column ("", header :"Actions", format:@<text>
<a class="ui-btn-inline ui-btn ui-icon-info ui-btn-icon-notext ui-corner-all" href="@Url.Action("Details", "Groups", new { id = item.gruppoId })">Info</a>
<a class="ui-btn-inline ui-btn ui-icon-delete ui-btn-icon-notext ui-corner-all" href="@Url.Action("Delete", "Groups", new { id = item.gruppoId })">Delete</a>
</text>, canSort : false)
}
)
@{Html.RenderPartial("Paging", Model);}
</div>
}
此页面显示包含某些行的表格。
我的怀疑是:
1)在我看来,这些行的内容取自 Model.Gruppi 集合的元素。因此,如果我想创建另一个包含存储在列表中对象中的信息的表,我只需要声明类似的东西:
wGrid.Bind(Model.MyCollection, rowCount: Model.TotalRows, autoSortAndPage: false);
是真的还是我错过了什么?
2)在我看来,模型对象是使用:
声明的@model MyUsers.Models.SearchGroups
但为什么当它使用模型访问对象字段时,它是否是模型对象的标准名称?
答案 0 :(得分:0)
1)是的,您认为网格绑定到模型上Gruppi集合中的项目(即MyUsers.Models.SearchGroups.Gruppi
)是正确的。这在视图中被引用为Model.Gruppi
。
如果您想在视图中创建另一个网格,您可以单独使用WebGrid构造函数,也可以使用上面代码中列出的构造函数和Bind方法的组合。对Bind的调用提供了传递分页网格行所需的附加数据的能力。构造函数和Bind方法都有许多参数可用。以下提供了可用选项的全面概述:
Get the Most out of WebGrid in ASP.NET MVC
2)视图顶部的模型指令
@model MyUsers.Models.SearchGroups
表示这是一个强类型视图,它绑定到MyUsers.Models.SearchGroups
类型的模型。 ASP.Net Mvc强类型视图使用Model
来引用绑定到视图的模型的实例。因此,在您看来,Model.Gruppi
指的是您模型上的Gruppi属性。