本文介绍了ModelState.IsValid限制在ASP.NET MVC 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是用 ModelState.IsValid 办理登机手续都在服务器端正确验证我的模型验证,但我认为就是用这种限制。比如我定义了一个远程验证属性,但如果我停用的JavaScript 然后 ModelState.IsValid 不检查远程验证,并始终返回true,问题出在哪里?这是 ModelState.IsValid 或者是我的错限制?如果需要的话我可以加我的所有的实现。

I always use ModelState.IsValid for check all of my model validation validated correctly in Server Side, but I think there is a limitation to use this. For example I define a Remote Validation attribute, but if I disable javascript then ModelState.IsValid don't check Remote Validation and always return true, Where is the problem? this is a limitation for ModelState.IsValid or is my fault? If necessary I can Add all my implementation.

推荐答案

这个问题已经绕了几圈。答案是:它不验证在服务器端,你必须自己执行验证操作。另请参见下面的SO帖子:

This question has come around a few times. The answer is: it doesn't validate on the server-side, you have to perform the validation action yourself. See also following SO posts:




  • asp.net mvc 3 serverside remote validation not working on submit through fiddler
  • RemoteAttribute validator does not fire server-side

当然,这将是很好能够反正来验证它的服务器端。幸运的是,一些老好人做它的实现。你可以找到他短暂的博客文章:。

Of course, it would be nice to be able to validate it anyway on the server-side. Luckily some nice guy made an implementation for it. You can find his short blog post: http://www.tugberkugurlu.com/archive/asp-net-mvc-server-side-remote-validation .

这篇关于ModelState.IsValid限制在ASP.NET MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 23:36