how do you decode/remove rich text in asp.net mvc 3 using razor?
I have a form that uses CKEditor and all works. I save the text "Description" in my case and all the rich text gets开发者_运维技巧 saved.So far so good.
Now in a particular page when retriving the "items" i would like the "description" text without the rich text how do you remove it?
What I have is
@Html.DisplayFor(modelItem=>item.Description)
I have tried to look for decode but cannot seem to find it.
How would you do it?
any suggestions Thanks a lot
EDITED Example text
What I get
<h3 style="color: red;"> <span style="color: rgb(0, 0, 0);">This is just an example</span>.<big>This is red.</big></h3> <p> <big>this is normal text</big></p>
What I want
This is just an exampleThis is red this is normal text
Try like this:
@Html.Raw(item.Description)
By using @Html.Raw
you assert that you realize all the consequences of not encoding user input. You assert that you realize the risks of XSS attacks, etc... that your site becomes vulnerable to and you assert as well to take great care of filtering this Description field.
You can add attribute DataType into your Model:
[DataType(DataType.Html)]
public string Description{get;set;}
精彩评论