I'm trying to concatenate 2 Html.ActionLink in a conditionnal column in a WebGrid. somethings like that :

@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>)
))
有帮助吗?

解决方案

If found the solution using:

 new HtmlString()

so this:

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>)

gives :

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())
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top