ModelState.AddModelError is not being displayed inside my view

后端 未结 3 1448
鱼传尺愫
鱼传尺愫 2020-12-13 08:50

I have the following view,, which create 10 ajax.beginform ,, But the problem that i am facing is that incase an error occurs during the creation of the object then the Mode

3条回答
  •  攒了一身酷
    2020-12-13 09:24

    You can use from ViewData dictionary in View to access ModelState data.

    For example:

    in Action:

    ModelState.AddModelError("CustomError", "Error 1");
    ModelState.AddModelError("CustomError", "Error 2");
    

    and to get "Error 1" message:

    ViewData.ModelState["CustomError"].Errors[0].ErrorMessage
    

提交回复
热议问题