HTML中的MVC RouteLink [英] HTML in MVC RouteLink
问题描述
我有一个RouteLink建造像这样
I have a RouteLink constructed like so
<p class="articleLink">
@MvcHelper.Html.RouteLink(article.Title, "Article_Route", new RouteValueDictionary() { { "articleId", article.Id }, { "seoUrl", article.SeoUrl } }))
</p>
然而, article.Title
可能包含HTML即值可以是&LT; EM&GT;采样&LT; / EM&GT;标题
从而获取呈现像这样
However, article.Title
could potentially contain HTML i.e. the value could be <em>Sample</em> Title
which in turn gets rendered like so
<a href="/Article/111111/Sample-Title"><em>Sample</em> Title</a>
有什么办法prevent被逃脱了HTML,而是被视为实际的HTML?或者我需要建立一个标准的HTML &LT; A HREF ...
在这种情况下链接(从而失去与RouteLink帮手相关联的所有细微)
Is there any way to prevent the HTML from being escaped, and instead to be treated as actual HTML? Or do I need to create a standard HTML <a href...
link in this case (thus losing all the niceties associated with the RouteLink helper).
推荐答案
如果你想你的HTML锚不要使用 Html.RouteLink
(因为它将HTML中EN code默认链接文本你是否注意到),而不是建立自己的通过手
标记使用 Url.RouteUrl
来生成的网址:
If you want HTML inside your anchor don't use the Html.RouteLink
(because it will HTML encode the link text by default as you noticed) instead of build your a
tag by hand with using Url.RouteUrl
to generate the url:
<p class="articleLink">
<a href="@(Url.RouteUrl("Article_Route",
new RouteValueDictionary()
{ { "articleId", article.Id },
{ "seoUrl", article.SeoUrl } }))">
@Html.Raw(article.Title)
</a>
</p>
或者你可以创建自己的非编码 RouteLink
帮手。
这篇关于HTML中的MVC RouteLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!