Asp.net mvc – how to show rich text without the html tags?

Issue

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.

enter image description here

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:

enter image description here

Database:

enter image description here

Now when I want to display the content to the User in a view (.cshtml), I DO NOT want to see the html tags.

enter image description here


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

Html Helper Raw will be use for your case.

@html.Raw("").

Answered By – Ronika

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.