How can I return a JSON result to a Ajax.BeginForm

后端 未结 6 1161
独厮守ぢ
独厮守ぢ 2021-02-02 08:49

I have got this simple form:

@using (Ajax.BeginForm(\"CreateProductFromAjaxForm\",\"Product\" , 
                  null, 
                  new AjaxOptions() {           


        
6条回答
  •  执笔经年
    2021-02-02 09:08

    JsonResult is just a kind of ActionResult derived class that indicates that this action will return JSON instead of a view or something else.

    For example:

     @using (Ajax.BeginForm("CreateProductFromAjaxForm","Product" , null, 
                  new AjaxOptions() {  OnSuccess = "getresult" }, null))
    

    This will generate a element which will send an AJAX request when submitted to the action. For this to work you need to include the following script to your page:

    Now all that's left is to write this onSuccess javascript function and process the JSON results returned by the server:

提交回复
热议问题