Asp.net mvc 3 webgrid中的If条件或for循环
在我看来,我正在使用这个webgridAsp.net mvc 3 webgrid中的If条件或for循环,asp.net-mvc-3,razor,webgrid,Asp.net Mvc 3,Razor,Webgrid,在我看来,我正在使用这个webgrid <div class="grid"> @{ var grid = new WebGrid(Model.SearchResults, canPage: true, rowsPerPage: 15); grid.Pager(WebGridPagerModes.NextPrevious); @grid.GetHtml( htmlAttributes: new { @style = "width:100%", cellspa
<div class="grid">
@{
var grid = new WebGrid(Model.SearchResults, canPage: true, rowsPerPage: 15);
grid.Pager(WebGridPagerModes.NextPrevious);
@grid.GetHtml(
htmlAttributes: new { @style = "width:100%", cellspacing = "0" },
columns: grid.Columns(
grid.Column(header: "Customer Name", format: (item) => Html.ActionLink((string)item.FullName, "ShowContracts", new { id = item.UserId }, new { @style = "color: 'black'", @onmouseover = "this.style.color='green'", @onmouseout = "this.style.color='black'" })),
grid.Column(header: "SSN", format: item => item.SSN)
))
}
</div>
@{
var grid=new WebGrid(Model.SearchResults,canPage:true,rowsPerPage:15);
Pager(WebGridPagerModes.NextPrevious);
@grid.GetHtml(
htmlAttributes:new{@style=“width:100%”,cellspacing=“0”},
列:grid.columns(
grid.Column(标题:“客户名称”,格式:(item)=>Html.ActionLink((string)item.FullName,“ShowContracts”,新的{id=item.UserId},新的{@style=“color:'black',@onmouseover=“this.style.color='green',@onmouseout=“this.style.color='black'”),
列(标题:“SSN”,格式:item=>item.SSN)
))
}
我用SSN搜索并在webgrid中显示结果。显示的数据是虚拟数据。
我在viewmodel中验证了一个bool account,现在我不应该给未验证的帐户提供操作链接,并在它们旁边显示文本,表示account verification pending。有人能帮我吗?试试以下方法:
grid.Column(
header: "Customer Name",
format: (item) =>
(bool)item.AccountVerified
? Html.ActionLink(
(string)item.FullName,
"ShowContracts",
new {
id = item.UserId
},
new {
style = "color: 'black'",
onmouseover = "this.style.color='green'",
onmouseout = "this.style.color='black'"
}
)
: Html.Raw("pending")
)
或者编写一个自定义HTML帮助程序来避免这种怪事,只需:
grid.Column(
header: "Customer Name",
format: item => Html.PendingLink(item)
)
请尝试以下操作:
grid.Column(
header: "Customer Name",
format: (item) =>
(bool)item.AccountVerified
? Html.ActionLink(
(string)item.FullName,
"ShowContracts",
new {
id = item.UserId
},
new {
style = "color: 'black'",
onmouseover = "this.style.color='green'",
onmouseout = "this.style.color='black'"
}
)
: Html.Raw("pending")
)
或者编写一个自定义HTML帮助程序来避免这种怪事,只需:
grid.Column(
header: "Customer Name",
format: item => Html.PendingLink(item)
)