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

 ̄綄美尐妖づ 提交于 2019-12-02 09:49:39

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.

.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>

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