本文介绍了Razor 语法可防止在 ActionLink 中转义 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP MVC 3 站点,我们正在尝试将一些样式添加到操作链接中.

I have an ASP MVC 3 site and we are trying to put some styling into the action links.

我希望 html 类似于 <a href="/somepath/someaction"><span class="someclass">some text</span>还有一些文本</a>,但我不知道如何告诉 Razor 正确渲染它的 .

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.

到目前为止我尝试过的:

What I've tried so far:

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

结果链接如下:some text</span>还有一些文字

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

结果链接如下:还有一些文字

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

导致编译错误.

想法?

推荐答案

ActionLink 方法不能接受 HTML.

The ActionLink method cannot take HTML.

您需要制作一个普通的标签,并使用@Url.Action(...)作为href.

You need to make a normal <a> tag, and use @Url.Action(...) for the href.

这篇关于Razor 语法可防止在 ActionLink 中转义 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!