AllowHtml attribute doesn't work

2019-04-12 16:59发布

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) enter image description here

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. enter image description here

1条回答
劳资没心,怎么记你
2楼-- · 2019-04-12 17:27

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)

查看更多
登录 后发表回答