I have a list of strings that i would like to display in cshtml page (Asp.net C#) ,the problem is instead of having html tags in my text i want to display the text formatted on the page when i run the website. the output is: <p><strong>some </strong><i>data</i></p>
it should be: some data
this is the C# code in cshtml page:
@foreach (var item in Model)
{
<div>@item.content</div>
}
You can replace HTML codes and tags with empty text using regex. Click here to verify regex
@foreach (var item in Model)
{
<div>@Regex.Replace(item.content, "<.*?>", String.Empty)</div>
}
You need to use Html.Raw()
so it renders as IHtmlString
in HTML instead of string
.
<div>@Html.Raw(item.content)</div>
Rendered HTML
<div><p><strong>some </strong><i>data</i></p></div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.