如何在 ASP.Net Core 中的 textarea 中显示纯文本而不是 HTMLText
这是我的看法
<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>
这是我的观点
如何在这个textarea中显示纯文本而不是HtmlText。
答案 0 :(得分:1)
如果您想显示不带任何格式的内容,可以使用 Regex.Replace(input, "<.*?>", String.Empty)
从字符串中去除所有 Html 标签。
您可以在后端更改:
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);
或者在前端更改:
@model TestModel
@using System.Text.RegularExpressions;
<textarea type="text" name="Decription" class="form-control">@Regex.Replace(Model.Decription, "<.*?>", String.Empty)</textarea>