How to use @Html.Raw() in @Html.TextAreaFor()

后端 未结 2 1690
一整个雨季
一整个雨季 2021-01-17 03:59

I am using summernote to add Image, Video, text. Also, I save image or video as Html Code that is type string to database. When I retreive video or image from the database

相关标签:
2条回答
  • 2021-01-17 04:22

    Html.Raw method returns System.Web.IHtmlString, I think what you need is just passing string property containing HTML tags (AFAIK Html.Raw helper can't be used inside other HTML helpers like DisplayFor or TextBoxFor).

    It is possible to use HttpUtility.HtmlDecode for Content property before TextAreaFor as shown by this example (especially if HTML tags are unknowingly encoded):

    @model Article
    
    @{
        Model.Content = HttpUtility.HtmlDecode(Model.Content);
    }
    
    @Html.TextAreaFor(x => x.Content, new { @class = "", placeholder = @Blog.Helper.Resources.Content, @id = "summernote_1" })
    

    By using this way, you can render HTML tags properly from viewmodel's string property without losing model binding.

    0 讨论(0)
  • 2021-01-17 04:35

    .textarea {
    padding: 2px;
    width: 250px;
    height: 200px;
    border: solid 1px #e0e0eb;
    overflow: scroll;
    overflow-y: scroll;
    overflow-x: hidden;
    }

    write your html content using @Html.Raw() inside a div that contains a class "textarea".

    <div class="textarea"> @Html.Raw(Model.NOTE) </div>

    0 讨论(0)
提交回复
热议问题