webdad3
webdad3

Reputation: 9080

encoding with Razor

I have text that is in the database like this : that does`nt

I'm upgrading this application and this is how it shows in MVC when I try to display it using this command:

@Html.DisplayFor(modelItem => item.adDescription)

I've tried to use the Html.Encode but I don't see a change. is there something I can do outside of updating the data in the DB to get it to display correctly?

Update - 2nd part of question:

How can I convert this bad text into good text when in Editing mode:

@Html.EditorFor(model => model.adDescription)

I keep getting dangerous text errors.

Upvotes: 0

Views: 77

Answers (1)

DarthVader
DarthVader

Reputation: 55112

Try following:

@Html.Raw(HttpUtility.HtmlDecode(@Model.ContentText))

Replace ContentText with your html code.

Can you try following?

<textarea>@Html.Raw(HttpUtility.HtmlDecode(@Model.ContentText))</textarea>

or if that is a input field. try accordingly.

Upvotes: 1

Related Questions