MVC WebGrid条件连接html . actionlink
本文关键字:html actionlink 连接 条件 WebGrid MVC | 更新日期: 2023-09-27 18:04:44
我正在尝试连接2个Html。WebGrid中条件列中的ActionLink。像这样:
@grid.GetHtml(columns:grid.Columns(
grid.Column("AccountNumber"),
grid.Column("ContractNumber"),
grid.Column("DisplayName"),
grid.Column("IsFinalized"," ",format:(item) => (item.IsFinalized == true)
?@<text> @Html.ActionLink("Edit", "Edit", new { accountId = item.AccountNumber}) | @Html.ActionLink("Details", "Details", new { accountId = item.AccountNumber }) </text>
:@<text> @Html.ActionLink("Validate", "Validate", new { accountId = item.AccountNumber} | @Html.ActionLink("Details", "Details", new { accountId = item.AccountNumber }))</text>)
))
如果使用
找到解决方案 new HtmlString()
:
grid.Column("IsFinalized"," ",format:(item) => (item.IsFinalized == true)
?@<text> @Html.ActionLink("Edit", "Edit", new { accountId = item.AccountNumber}) | @Html.ActionLink("Details", "Details", new { accountId = item.AccountNumber }) </text>
:@<text> @Html.ActionLink("Validate", "Validate", new { accountId = item.AccountNumber} | @Html.ActionLink("Details", "Details", new { accountId = item.AccountNumber }))</text>)
给:
grid.Column("IsFinalized", " ", format: item => (item.IsFinalized == true)
? new HtmlString( Html.ActionLink("Edit", "Edit", new { accountId = item.AccountNumber }).ToString() + "|" + Html.ActionLink("Details", "Details", new { accountId = item.AccountNumber }).ToString())
: new HtmlString( Html.ActionLink("Validate", "Validate", new { accountId = item.AccountNumber }).ToString() + "|" + Html.ActionLink("Details", "Details", new { accountId = item.AccountNumber }).ToString())