ASP.NET MVC ValidateInput(false) stops working with xVal and [RegularExpression] DataAnnotation

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 22:31:31

No, it was an issue in MVC 1 + xVal. In MVC 2 the validation works as supposed (and there's no need for xVal anymore) – Alex42

Looks like the bot keeps on pushing this one to the top still. Could you mark an answer as accepted so that it knows?

I'm using xVal & nhibernate.validator and i tried to reproduce this behavior but because the validator is tied into the client side I couldn't get a value of past the client side validation. when i disabled javascript, it got to the server side validation, and was caught by the regular expression validator.

I tried the same thing with using the data annotations validation attributes and model binder and it made it past as well.

there must be something else going on that is causing the error. Sorry I couldn't be more helpful!

Matt Kocaj

Try validating using a simple rule with this method. This can at least eliminate xVal from the equation. If the problem persists then i'd suggest it's related to either:

  • the implementation of MVC's default Model Binder
  • or there is a problem with the MVC view engine in the release your using that's somehow allowing an exception to be made for the attribute you specified by validating the < when it shoudn't be

if it just a field, you could just write a routine to look for a character '< or >' and remove it. you can achieve this by by making use of substring. hope this this helps

  • use For loop to length of text to be tested (for (int i=1, i <= text.length, ++))
  • verify each character begining 1 (e.g ch = text.substring(i,1)
  • add each read character to tmp string except '< or >'

I suppose the static method Escape() would solve this for you.

  Regex r = new Regex(Regex.Escape(expression));

Put this line in web.config

<httpRuntime requestValidationMode="2.0" />

This is change in ASPNET 4.0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!