asp.net MVC ModelState.IsValid returning false

强颜欢笑 提交于 2019-12-06 07:18:13

I can see a few solutions:

  1. After fixing the format in your model binder, you could clear the ModelState error with ModelState["SampleDate"].Errors.Clear();.
  2. Use JavaScript to validate the input to force the user to enter the correct format.
  3. Use JavaScript to change the format for the user before form post.

I think a combination of 1 and 2 is your best bet.

Try using in your action a white list of parameters to bind, with

Bind(Include="param1,param2...")

And in that list, ommit the parameter that you are binding by yourself. Read this ScottGu's post for more information.

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