What's the recommended way to report model state and application errors to client?

天大地大妈咪最大 提交于 2019-12-05 18:28:00

Don't handle validation by throwing exceptions. If you are sending a JSON response include all that's needed to the client in the JSON response:

return Json(new JsonAuth { 
    Success = false, 
    Message = "The email you entered does not exist in our system.  Please enter the email address you used to sign up.", 
    ReturnUrl = "/Home/" 
});

and if you are returning a view add a model state error and the HTML helpers on your form will do the rest:

ModelState.AddModelError("email", "The email you entered does not exist in our system.  Please enter the email address you used to sign up.");
return View();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!