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

后端 未结 3 893
野的像风
野的像风 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:28

    The RedirectToAction method returns 302 which causes the client to be redirected. Because of this the ModelState is lost as the redirect is a new request. You could however, use the TempData property which allows you to store a temporary piece of data that is unique to the session. You could then check for this TempData on the other controller and add a ModelState error in that method.

提交回复
热议问题