Reputation: 7979
I have
<%= Html.TextArea("PostContent.Description", Model.PostContent.Description)%>
if I enter
"I am <script>alert()</script> After scrip",
I will get<p>I am <script>alert()</script> After scrip</p>
by default.
but i don't want this behavior. how can i turn off this default behavior only for this text box
Note that i just want to handle this text box only.
[mvc 2]
Upvotes: 0
Views: 254
Reputation: 7979
i found that it is not possible to avoid default encoding by mvc
Upvotes: 0
Reputation: 8667
In order to prevent the binder from escaping the HTML characters you can mark the Description
property with an [AllowHtml]
attribute:
public class ModelPostContent
{
[AllowHtml]
public string Description { get; set; }
}
Upvotes: 3
Reputation: 5334
Try this:
<textarea name="<%= HtmlHelper.GenerateIdFromName("PostContent.Description") %>">
<%= Model.PostContent.Description %>
</textarea>
Upvotes: 1