且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

客户端验证不在Asp.net MVC4中工作

更新时间:2022-04-19 21:57:34

此处如果模型状态无效,您将返回相同的状态通过RedirectToAction翻页,而不是你应该返回与模型相同的视图,以便验证消息被绑定。

Here if the model state is not valid, you are returning back to the same page through RedirectToAction, rather you should return the same view with the model so that the validation message gets binded.
return View(model); //model that the view expects..





或其他方式是如果modelState无效那么,

你可以使用



or another way is if modelState is not valid then,
you can use

ModelState.AddModelError("ModelPropertyName","Error Message")//if the data annotations are                      not used
return View(model);



我希望这有帮助。

如果有的话,回复你的查询。

谢谢。


I hope this helps.
Post back your queries if any.
Thanks.