0

How to display plain text instead of with HTMLText in textarea in ASP.Net Core

this is my view

<div class="form-group row">
                <label asp-for="Decription" class="col-sm-3 col-form-label">Description</label>
                <div class="col-sm-7">
                    <textarea type="text" asp-for="Decription" class="form-control"></textarea>
                </div>
            </div>

This is my View

enter image description here

How to display plain text in this textarea instead of HtmlText.

  • 1
    Hi @Abhay,Your code is working as it should, but ` – Rena Jun 23 '21 at 07:19
  • @Html.Raw("your html text") – Nima Talebi Jun 23 '21 at 07:19
  • check this [Link](https://stackoverflow.com/questions/4705848/rendering-html-inside-textarea) – Nagib Mahfuz Jun 23 '21 at 07:36
  • I have already use CKEditor but this Is use only for admin and this is client-side and my client-side requirement is not to show editor just show textarea and those data. – Abhay Babariya Jun 23 '21 at 09:15

1 Answers1

2

If you want to show your content without any formatting, you could use Regex.Replace(input, "<.*?>", String.Empty) to strip all of Html tags from your string.

You could change in backend:

var model = new TestModel() { 
       Decription="<p><strong>Test</strong> is a Special Item in our <i>Restraunt</i>.</p>" 
};
model.Decription = Regex.Replace(model.Decription, "<.*?>", String.Empty);

Or change in frontend:

@model TestModel

@using System.Text.RegularExpressions;

<textarea type="text" name="Decription" class="form-control">@Regex.Replace(Model.Decription, "<.*?>", String.Empty)</textarea>
Rena
  • 30,832
  • 6
  • 37
  • 72
  • Thank you for helping me, If we change only in view then it also works. no need to use in backend controller side **Regex.Replace(model.Decription, "<.*?>", String.Empty);** If we use only frontend side then also work. – Abhay Babariya Jun 24 '21 at 06:42