Ajax.BeginForm OnFailure invoked when ModelState is InValid

前端 未结 2 1698
悲哀的现实
悲哀的现实 2021-02-02 04:19

I want to call \"OnFailure\" when ModelState is not valid in controller.

In My LoginView

 @using (Ajax.BeginForm(\"Login\", new AjaxOptions { HttpMethod         


        
2条回答
  •  一向
    一向 (楼主)
    2021-02-02 04:35

    When you detect the problem in the ModelState, set the StatusCode of the response object to something like 400 (You can get the code from the System.Net.HttpStatusCode class)

    That will fire the onfailure method.

    Si

提交回复
热议问题