AllowHtml属性不起作用 [英] AllowHtml attribute doesn't work

查看:1349
本文介绍了AllowHtml属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现微小MCE文本编辑器来我的创建页。我使用 [AllowHtml] 属性到我的机身属性,但它仍然无法正常工作。我的博客详细视图仍呈现HTML标签。

I'm trying to implement Tiny MCE text editor to my Create page. I've used [AllowHtml] attribute to my Body property but it still doesn't work. My detail view for the blog still showing html tags.

这是我的博客实体类。

public class Blog
{
    public int Id { get; set; }

    [Required]
    public string Title { get; set; }

    [AllowHtml]
    [Required]
    [DisplayName("Content")]
    public string Body { get; set; }

    [DisplayName("Created on")]
    [DataType(DataType.Date)]
    [Required]
    public DateTime Created { get; set; }

}



PIC的下方显示了我创建的博客页面(这节目我有TinyMCE的实现的属性和工作)

The pic below shows my create blog page (which shows that I have TinyMCE implemented property and working)

这下面的图片显示我的详细信息页面的博客。这里的问题是,它展示的剧照,尽管我已经允许HTML到我的机身属性HTML标签。

This pic below shows my detail page for a blog. The problem here is that it stills showing html tags even though I've allowed html to my Body property.

推荐答案

AllowHtml属性只是模型绑定,通过不验证(白名单的HTML标记)对HTML标签帮助。它没有做任何事情与UI。

AllowHtml attribute just helps with model binding , by not validating(white listing html tags) against html tags . It does not do any thing with UI.

要显示的文本值,而不是HTML编码,你可以使用 @ Html.Raw(型号.property)

To display the text value and not html encode it, you can use @Html.Raw(Model.property)

这篇关于AllowHtml属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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