Get error message if ModelState.IsValid fails?

前端 未结 11 1284
离开以前
离开以前 2020-11-30 02:27

I have this function in my controller.

[HttpPost]
public ActionResult Edit(EmployeesViewModel viewModel)
{
    Employee employee = GetEmployee(viewModel.Empl         


        
11条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 02:43

    You can do this in your view without doing anything special in your action by using Html.ValidationSummary() to show all error messages, or Html.ValidationMessageFor() to show a message for a specific property of the model.

    If you still need to see the errors from within your action or controller, see the ModelState.Errors property

提交回复
热议问题