Entering HTML/XML into HTML.TextBoxFor generated inputs
I have constructed a form in ASP.NET MVC 2 that is bound to a Model, using code similar to below to generate my inputs and wrapping them within Ajax.BeginForm("MyAction")
.
<%: Html.TextBoxFor(Function(m) Model.SomeProperty, New With {.class = "myClass"})%>
This all seems to work fine until I enter text such as <html>
, at which point the Action my form is pointing to is no longer hit. I've tried a number of different combinations of input 开发者_JAVA百科text, and it seems to only stop working when entering some form of HTML/XML.
Is this a known issue with the TextBoxFor
method in general, or am I missing something?
Have you disabled request validation?
By default, the ASP.NET MVC framework prevents you from submitting form data that contains potentially malicious content. This feature is called request validation.
It sounds like that could be the cause. Try adding the following attribute to your action method to disable it
[ValidateInput(false)]
If you are using .Net 4.0 you will also have to set the validation mode in your web.config file
<httpRuntime requestValidationMode="2.0" />
精彩评论