相关疑难解决方法(0)

Razor语法可防止在ActionLink中转义HTML

我有一个ASP MVC 3网站,我们正试图在动作链接中加入一些样式.

我希望html是类似的<a href="/somepath/someaction"><span class="someclass">some text</span> some more text</a>但我无法弄清楚如何告诉Razor <span>正确渲染它.

到目前为止我尝试过的:

@Html.ActionLink("<span class="someclass">some text</span> some more text", SomeAction, SomeController);
Run Code Online (Sandbox Code Playgroud)

导致链接看起来像: <span class="someclass">some text</span> some more text

@Html.ActionLink("<text><span class="someclass">some text</span></text> some more text", SomeAction, SomeController);
Run Code Online (Sandbox Code Playgroud)

导致链接看起来像: <text><span class="someclass">some text</span></text> some more text

@Html.ActionLink(<text>"<span class="someclass">some text</span> some more text"</text>, SomeAction, SomeController);
Run Code Online (Sandbox Code Playgroud)

导致编译错误.

思考?

c# razor asp.net-mvc-3

12
推荐指数
1
解决办法
3562
查看次数

标签 统计

asp.net-mvc-3 ×1

c# ×1

razor ×1