剃刀语法prevents在ActionLink的HTML转义 [英] Razor syntax prevents escaping HTML in an ActionLink

查看:150
本文介绍了剃刀语法prevents在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><跨度类=SomeClass的>有的文字< / SPAN>一些文字< / A> ,但我无法弄清楚如何告诉剃刀呈现<跨度方式> 它的正确

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.ActionLink("<span class="someclass">some text</span> some more text", SomeAction, SomeController);

的结果,看起来像一个链接:&LT;跨度类=SomeClass的&GT;有的文字&lt; / SPAN&GT;一些文字

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

的结果,看起来像一个链接:&LT;文本&GT;&LT;跨度类=SomeClass的&GT;有的文字&lt; / SPAN&GT;&LT; /文本&GT;一些文字

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

导致编译错误。

思考?

推荐答案

ActionLink的方法不能把HTML

The ActionLink method cannot take HTML.

您需要做一个正常的&LT; A&GT; 标记,并使用 @ Url.Action(...)的href

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆