First Last

First Last

  • NA
  • 648
  • 73.3k

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

Aug 24 2020 12:54 PM
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 the entry from the database and shows the html tags.
 
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):
  1. @model GbngWebClient.Models.BlogPublishedByBlogIdVM    
  2. <h2 class="page-header"><span class="blogtitle">@Session["BlogTitle"]</span></h2>    
  3. @{    
  4. Layout = "~/Views/Shared/_LayoutUser.cshtml";    
  5. }    
  6. <div>    
  7. <a href="@Url.Action("LoadDropdownBlogCategorysInBlogsPublished", "BlogPublished")">Return To Select a Blog</a>    
  8. </div>    
  9. <br />    
  10. @if (Model != null)    
  11. {    
  12. @Html.LabelFor(model => model.BlogPublishedByBlogId.CreatedDateTime)    
  13. @Html.TextBoxFor(model => model.BlogPublishedByBlogId.CreatedDateTime, new { @class = "form-control", @disabled = "disabled" })    
  14. @Html.LabelFor(model => model.BlogPublishedByBlogId.ModifiedDateTime)    
  15. @Html.TextBoxFor(model => model.BlogPublishedByBlogId.ModifiedDateTime, new { @class = "form-control", @disabled = "disabled" })    
  16. @Html.DisplayFor(model => model.BlogPublishedByBlogId.BlogContent, new { @class = "form-control blogContent", @disabled = "disabled" })    
  17. } 
Here are the models (not showing all of the properties):
  1. namespace GbngWebClient.Models    
  2. {    
  3. public class BlogPublishedByBlogIdVM    
  4. {    
  5. public BlogPublishedByBlogIdVM()    
  6. {    
  7. this.BlogPublishedByBlogId = new BlogPublishedByBlogId();    
  8. }    
  9. public BlogPublishedByBlogId BlogPublishedByBlogId { getset; }    
  10. }    
  11. }    
  12. using System;    
  13. using System.ComponentModel.DataAnnotations;    
  14. namespace GbngWebClient.Models    
  15. {    
  16. public class BlogPublishedByBlogId    
  17. {    
  18. [Required]    
  19. [Display(Name = "Content")]    
  20. public string BlogContent { getset; }    
  21. }    
  22. } 

Answers (1)