我将 List 作为模型传递给 WebGrid 构造函数。
@model List<string>
@{
var grid = new WebGrid(Model);
}
<div>
@grid.GetHtml()
</div>
我期待得到我的带有网格的字符串列表。但我得到了字符串的长度。奇怪的?
我将 List 作为模型传递给 WebGrid 构造函数。
@model List<string>
@{
var grid = new WebGrid(Model);
}
<div>
@grid.GetHtml()
</div>
我期待得到我的带有网格的字符串列表。但我得到了字符串的长度。奇怪的?
这很奇怪,但解释是WebGrid查找行对象的公共属性以便将它们显示为列;碰巧Length是String类型公开的唯一属性。
请注意,您可以通过明确指定格式来获得所需的行为:
@grid.GetHtml(
columns: new[] {
g.Column(format: (item) => item)
}
)
@{
Boolean access = ViewBag.accesscontrols;
}
<h1 class="header_text_pink">Vendor Master List<img
src='@Url.Image("~/content/images/question_mark.png")' alt="" class="information_icon"
/></h1>
<span>@Html.RenderNotificationMessage()</span>
<div class="si_top_main_table" id="tableDiv_Arrays">
<div class="search_pink">
<div class="tablesorter_pink" id="targetContainer">
@{
List<FCC.POSS.Common.Models.Employee> listmodel = ViewBag.EmployeeList;
ViewBag.Title = "Employee Master";
}
@if (listmodel != null)
{
if (listmodel.Count > 0)
{
List<WebGridColumn> gridColumn = new List<WebGridColumn>();
var grid = new WebGrid(source: listmodel,
rowsPerPage: listmodel.Count(),
canSort: true,
canPage: true);
gridColumn.Add(grid.Column("Fname", header: "First Name"));
gridColumn.Add(grid.Column("Lname", header: "Last Name"));
gridColumn.Add(grid.Column("Address", header: "Address"));
gridColumn.Add(grid.Column("City", header: "City"));
gridColumn.Add(grid.Column("Phoneno", header: "Phone no"));
gridColumn.Add(grid.Column("Passportno", header: "Passport no"));
gridColumn.Add(grid.Column("Civilid", header: "Civil Id"));
gridColumn.Add(grid.Column("Gender", header: "Gender"));
gridColumn.Add(grid.Column("Createddt", header: "Created Date"));
gridColumn.Add(grid.Column("Deleteddt", header: "Deleted Date"));
gridColumn.Add(grid.Column("Isdelete", header: "Is Deleted ?"));
// gridColumn.Add(grid.Column("View", format:@<text><span style=" background-
color:Blue;
color:Green">@Html.ModalDialog("View","ag",null,Url.Action("Details","Employee",new
{item.Id}),false)</span></text>));
@grid.GetHtml(
tableStyle:"display tablesorter_usermaster",
columns:grid.Columns(gridColumn.ToArray()),
htmlAttributes: new { id = "mst_WebGrid", @style = "width:100%;" });
}
}
</div>
</div>
</div>
<h2>Index</h2>