Validating form using ModelState

后端 未结 1 703
醉话见心
醉话见心 2021-01-07 03:15

I am trying to validate a form using ModelState generally the same way as in tutorials on asp.net/mvc. However I dont have my own database or their objects and want to valid

相关标签:
1条回答
  • 2021-01-07 04:00

    So, for every error you add with ModelState.AddModelError() and call the View again, MVC Framework will try to find an AttemptedValue for every error it finds. Because you didn't add them, MVC will throw an exception.

    http://forums.asp.net/p/1396019/3006051.aspx

    If there are errors then you must also set the model value as well as the modal error

    ModelState.AddModelError("Some_Key","Show some error message");
    ModelState.SetModelValue("Some_Key", ValueProvider["Some_Key"]);
    
    0 讨论(0)
提交回复
热议问题