Using HTML tags inside linkText of Html.ActionLink

前端 未结 4 950
星月不相逢
星月不相逢 2020-12-06 16:15

Is it possible to use HTML tags in the linkText of Html.ActionLink? For instance, if I wanted to bold part of the text of a link I would try something similar to this:

4条回答
  •  臣服心动
    2020-12-06 16:58

    This works for me:

    @Html.Raw(@Html.ActionLink("XXX", "Index", new { }, new { @class = "FormBtn" }).ToHtmlString().Replace("XXX","Back to List"))
    

    Essentially use the ActionLink to create the html with a placeholder for what you want to replace ('XXX'), then convert it an HTML String, replace the placeholder with your markup, render the string as HTML.Raw.

提交回复
热议问题