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