简体   繁体   English

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

[英]Razor syntax prevents escaping HTML in an ActionLink

I have an ASP MVC 3 site and we are trying to put some styling into the action links. 我有一个ASP MVC 3网站,我们正在尝试将一些样式放入动作链接。

I want the html to be something like <a href="/somepath/someaction"><span class="someclass">some text</span> some more text</a> but I can't figure out how to tell Razor to render the <span> of it correctly. 我希望html类似于<a href="/somepath/someaction"><span class="someclass">some text</span> some more text</a>但我无法弄明白如何辨别剃刀正确渲染它的<span>

What I've tried so far: 到目前为止我尝试过的:

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

results in a link that looks like: <span class="someclass">some text</span> some more text 导致链接看起来像: <span class="someclass">some text</span> some more text

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

results in a link that looks like: <text><span class="someclass">some text</span></text> some more text 产生如下链接: <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);

results in a compilation error. 导致编译错误。

Thoughts? 思考?

The ActionLink method cannot take HTML. ActionLink方法无法使用HTML。

You need to make a normal <a> tag, and use @Url.Action(...) for the href . 你需要制作一个普通的<a>标签,并使用@Url.Action(...)作为href

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM