Get error message if ModelState.IsValid fails?

前端 未结 11 1266
离开以前
离开以前 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:34

    If anyone is here for WebApi (not MVC) you just return the ModelState object:

    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);

提交回复
热议问题