2012-05-11 17 views

回答

2

這很奇怪,但是解釋是WebGrid查找行對象的公共屬性以便將它們顯示爲列;它正好碰巧長度是唯一的屬性類型字符串暴露。

請注意,您可以通過指定格式明確地得到您想要的行爲:

@grid.GetHtml(
    columns: new[] { 
     g.Column(format: (item) => item) 
    } 
) 
+0

得到它dbaseman,謝謝!我是mvc3的新手,webgrid是非常有用的幫手 – ttacompu

0
@{ 
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>