问题
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.
回答1:
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 .
来源:https://stackoverflow.com/questions/10494168/limitation-of-modelstate-isvalid-in-asp-net-mvc-3