0
grid.Column(format:
    v =>
            @Html.ActionLink(@item.Name, "Details", new { id = item.Id }).ToString() + 
            (v.State == State.Y 
                 ? @Html.ActionLink("Start", "Start", new { id = v.Id }) 
                 : (v.State == State.Z)
                       ? @Html.ActionLink("Continue", "Start", new { id = v.Id }) 
                       : MvcHtmlString.Create("")).ToString()
)

This solution gives me a encoded HTML, What can I Do Instead?

Andy T
  • 10,223
  • 5
  • 53
  • 95
Yacov
  • 1,060
  • 14
  • 27

2 Answers2

0

This answer is based upon the SO Question found here

The idea is to use tags to allow Razor markup and content to be mixed.

Sample:

<text>
    @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
    @Html.ActionLink("Details", "Details", new { id = item.Id })
    @if(item.State == State.Y)
    {
        @: | @Html.ActionLink("Continue", "Start", new { id = item.Id })
    }
</text> 
Community
  • 1
  • 1
Yacov
  • 1,060
  • 14
  • 27
0

There is a Razor HtmlHelper called Raw() which will do exactly what you need, it outputs content without performing HTML encoding. So you could use @Html.Raw(Html.ActionLink(...) + " " + Html.AmctionLink(...)) and you will get the HTML for your action links, combined by spaces or whatever character you are using as a separator.

The accepted answer is not valid Razor markup, the @ symbol must be followed by ":", "(" or a C# identifier. The first line should simply be . I also feel that having to use so many content identifiers( and @:) makes it more error-prone and difficult to read/type. Please consider changing the correct answer if it is not corrected.

Scott Simontis
  • 748
  • 1
  • 10
  • 24