Abhay Babariya
Abhay Babariya

Reputation: 25

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

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.

Upvotes: 0

Views: 756

Answers (1)

Rena
Rena

Reputation: 36655

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>

Upvotes: 2

Related Questions