我正在使用Mvc 5 razor,并且已经使用ckeditor来保存数据库中的数据但是当我在视图上检索数据时它会带来所有的html标签请帮助我们如何在视图上以正常文本形式显示它/ p>
<div class="panel panel-default">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" id="Inclusions">
<div class="panel-heading">
<h4 class="panel-title"> INCLUSIONS </h4>
</div>
</a>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
@Html.Raw(Html.DisplayFor(Model => Model.Itinerarydetail.Inclusions));
</div>
</div>
</div>
答案 0 :(得分:2)
当您使用Html.DisplayFor
辅助方法时,razor会在渲染之前对内容进行编码。您应该使用Html.Raw()
辅助方法,它不会对您的内容进行编码,并将您想要直接渲染的值传递给它。
<div class="panel-body">
@Html.Raw(Model.Itinerarydetail.Inclusions)
</div>
答案 1 :(得分:1)
Here in my view when you get data from database use @Html.Raw
<div class="form-group">
@Html.LabelFor(model => model.Description,htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-sm-8">
<textarea type="text" class="ckeditor" name="Description">@item.Description</textarea>
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
</div>