[英]Asp.net mvc - how to show rich text without the html tags?
I DO NOT want to show the html tags in the content to the User.我不想在内容中向用户显示 html 标签。 How to I do that?
我该怎么做?
I have a maintenance app that adds/edits blog content.我有一个维护应用程序可以添加/编辑博客内容。 It has a rich text editor.
它有一个富文本编辑器。
When the content is saved in the SQL server database in a column defined as varchar(max), it saves it with html tags.当内容保存在 SQL 服务器数据库中定义为 varchar(max) 的列中时,它使用 html 标签保存它。
The edit feature retrieves it from the database and shows that:编辑功能从数据库中检索它并显示:
Database:数据库:
Now when I want to display the content to the User in a view (.cshtml), I DO NOT want to see the html tags.现在,当我想在视图 (.cshtml) 中向用户显示内容时,我不想看到 html 标签。
Here is the view (not showing all of the code):这是视图(未显示所有代码):
@model GbngWebClient.Models.BlogPublishedByBlogIdVM
<h2 class="page-header"><span class="blogtitle">@Session["BlogTitle"]</span></h2>
@{
Layout = "~/Views/Shared/_LayoutUser.cshtml";
}
@if (ViewBag.errormessage != null)
{
<p class="alert alert-danger" id="errorMessage">@ViewBag.errormessage</p>
}
<br />
<div>
<a href="@Url.Action("LoadDropdownBlogCategorysInBlogsPublished", "BlogPublished")">Return To Select a Blog</a>
</div>
<br />
@if (Model != null)
{
<div class="panel panel-default toppanel">
<div class="panel-body">
<div class="row">
<div class="col-md-2">
@Html.LabelFor(model => model.BlogPublishedByBlogId.CreatedDateTime)
@Html.TextBoxFor(model => model.BlogPublishedByBlogId.CreatedDateTime, new { @class = "form-control", @disabled = "disabled" })
</div>
<div class="col-md-2">
@Html.LabelFor(model => model.BlogPublishedByBlogId.ModifiedDateTime)
@Html.TextBoxFor(model => model.BlogPublishedByBlogId.ModifiedDateTime, new { @class = "form-control", @disabled = "disabled" })
</div>
</div>
<br />
<div class="row">
<div>
@Html.DisplayFor(model => model.BlogPublishedByBlogId.BlogContent, new { @class = "form-control blogContent", @disabled = "disabled" })
</div>
</div>
<br />
}
Here are the models (not showing all of the properties):以下是模型(未显示所有属性):
namespace GbngWebClient.Models
{
public class BlogPublishedByBlogIdVM
{
public BlogPublishedByBlogIdVM()
{
this.BlogPublishedByBlogId = new BlogPublishedByBlogId();
}
public BlogPublishedByBlogId BlogPublishedByBlogId { get; set; }
}
}
using System;
using System.ComponentModel.DataAnnotations;
namespace GbngWebClient.Models
{
public class BlogPublishedByBlogId
{
[Required]
[Display(Name = "Content")]
public string BlogContent { get; set; }
}
}
Use利用
@Html.Raw(Model.BlogContent)
Html Helper Raw 将用于您的案例。
@html.Raw("").
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.