0

I need to allow symbols < > but also prevent XSS attacks, so I'm trying to use HTML.Encode() method:

 @Html.TextAreaFor(model => Model.Text, 15, 5,
 new { placeholder = ReviewResources.ReviewPlaceholder, data_val = "true",
 data_val_regex=ReviewResources.IllegalSymbolsMessage,
 data_val_regex_pattern="^[^<>]+$"}

Changing for:

 @Html.TextAreaFor(model => @Html.Encode(Model.Text), 15, 5,
 new { placeholder = ReviewResources.ReviewPlaceholder, data_val = "true"}

But I'm getting an exception:

 {"Templates can be used only with field access, property access, 
single-dimension array index, or single-parameter custom indexer expressions."}

How to use correctly encoding from < to &lt; and et cetera?

2
  • You need to explain what you're trying to do better. You need to allow angle brackets for what purpose?
    – Casey
    Commented Sep 3, 2014 at 17:16
  • i just needed them for "=>"symbols or math operations (a>b) Commented Sep 3, 2014 at 17:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.