[英]How to render html as text
<td>
@(vehicle.SearchResult.Mpg == null ?
Html.Raw("<a href='Model.ContactDealerUrl'>Please Contact Dealer</a>") :
vehicle.SearchResult.Mpg + " " + Html.GetResourceTranslation("UclMpg").ToHtmlString())
</td>
Hi, I'm new to stack overflow but I'm trying to render the html tag as a link text, such as 'Please Contact Dealer' but when rendered unto the browser returns as 'Please Contact Dealer'. 嗨,我是堆栈溢出的新手,但是我试图将html标签呈现为链接文本,例如'Please Contact Dealer',但是在呈现给浏览器时返回为'Please Contact Dealer'。 Any help on how to fix this will be much appreciated.
任何有关如何解决此问题的帮助将不胜感激。
Thank you 谢谢
If I understand your problem, following details may help you fix the behavior. 如果我了解您的问题,请遵循以下详细信息可以帮助您解决问题。
If your original code looks like: 如果您的原始代码如下所示:
@Html.Raw("<a href='Model.ContactDealerUrl'>Please Contact Dealer</a>").ToHtmlString()
then remove the ToHtmlString()
and make else part in the conditional expression also to return IHtmlString
(label/link etc., element). 然后删除
ToHtmlString()
并在条件表达式中加入其他部分,以返回IHtmlString
(标签/链接等元素)。
If ToHtmlString()
on @Html.Raw(...)
is called then it render the raw Html string instead of element. 如果
ToHtmlString()
上@Html.Raw(...)
被调用则呈现原始的HTML字符串,而不是元素。
Invalid: @(some condition? IHtmlString : string)
. 无效:
@(some condition? IHtmlString : string)
。 In a conditional expression the true/false return Type
should be same or implicitly convertible. 在条件表达式中,true / false返回
Type
应该相同或可以隐式转换。
Hope this help you... 希望这对您有帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.