简体   繁体   English

HTML.DisplayFor将标签显示为纯文本

[英]Html.DisplayFor shows tags as plain text

<div id="contact-description">
    @Html.DisplayFor(model => model.Description)
</div>

屏幕截图

This is the output this code gives, while the output should only be "Test". 这是该代码给出的输出,而输出只能是“ Test”。 How to hide the Span tag? 如何隐藏Span标签?

Presuming your Description property value contains HTML tags (the <span> ): 假设您的Description属性值包含HTML标记( <span> ):

You want @Html.Raw(Model.Description) . 您需要@Html.Raw(Model.Description) @Html.DisplayFor will automatically delimit HTML to prevent HTML injection. @Html.DisplayFor将自动分隔HTML以防止HTML注入。 If your expecting HMTL output use Raw() 如果您期望的HMTL输出使用Raw()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM