'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. 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.
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.
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; }
}
}
Solution 1:[1]
Html Helper Raw will be use for your case.
@html.Raw("").
Solution 2:[2]
Use
@Html.Raw(Model.BlogContent)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ronika |
| Solution 2 | Obonyo Fredrick |




