Sinaesthetic
Sinaesthetic

Reputation: 12192

How do I have dangerous request return a validation error instead of throwing an exception?

So MVC is throwing a dangerous request error when submitting a form value containing markup (e.g. <http://www.stuff.com>). Is it possible to have the form validation still work but return a Model state error instead of throwing a dangerous request exception?

Upvotes: 0

Views: 58

Answers (1)

tophallen
tophallen

Reputation: 1063

there are a few options, you could use the attribute [AllowHtml] and then check for html server side, and then add model state errors and return, or you could also use a hidden field, and encode it so that the < becomes &lt; a few other options are listed here and here on the validation part.

I would suggest looking at HtmlEncode, as there may or may not be a legitimate case for someone to write < or > in a field.

Upvotes: 1

Related Questions