AllowHtml attribute doesn't work

别说谁变了你拦得住时间么 提交于 2019-12-06 10:57:54

问题


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.

This is my blog entity class.

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; }

}

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

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.


回答1:


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.

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



来源:https://stackoverflow.com/questions/29859208/allowhtml-attribute-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!