[英]Mvc not format a href link
I have mvc project. 我有MVC项目。 On controller I format link next way:
在控制器上,我格式化链接的另一种方式:
user.ShortBiography = user.LongBiography.Substring(0, 100) + "... <a href=\"#\">Read more</a>";
On Views the HTML format next way: 开以下列方式查看HTML格式:
<p>@Html.DisplayFor(score => item.ShortBiography)</p>
When I open site on browser, I see this result: 当我在浏览器上打开网站时,看到以下结果:
Some text ... <a href="#">Read more</a>
So.MVC doesn't format link. 因此,MVC不格式化链接。 I see only text with tags.
我只看到带有标签的文本。 So.
所以。 How it's fix?
如何解决?
You will need to either make ShortBiography a HtmlString or you will need to do this: 您需要将ShortBiography设置为HtmlString,或者需要执行以下操作:
@Html.Raw(item.ShortBiography)
I have also used helpers which convert string to HtmlString 我还使用了将字符串转换为HtmlString的帮助器
@Html.DisplayFor(score => item.ShortBiography.ToHtmlString())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.