How to add ModelState.AddModelError message when model item is not binded

后端 未结 3 892
野的像风
野的像风 2021-02-01 05:15

I am new to MVC4. Here I added the ModelState.AddModelError message to display when the delete operation is not possible.

  
    

        
3条回答
  •  既然无缘
    2021-02-01 05:27

    RedirectToAction will clear ModelState. You must return a view in order to use this data. Therefore, the first if case won't work. Also, ensure that you have a control in your view (like ValidationSummary) which displays the error... this could be the problem in the second case.

提交回复
热议问题