How to post ASP.NET MVC Ajax form using JavaScript rather than submit button

后端 未结 8 623
小鲜肉
小鲜肉 2020-11-30 23:20

I have a simple form created using Ajax.BeginForm:

<% using (Ajax.BeginForm(\"Update\", \"Description\", new { id = Model.Id         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 00:19

    Simply place normal button indide Ajax.BeginForm and on click find parent form and normal submit. Ajax form in Razor:

    @using (Ajax.BeginForm("AjaxPost", "Home", ajaxOptions))
        {        
            
    }

    and Javascript:

    function submitParentForm(sender) {
        var $formToSubmit = $(sender).closest('form');
    
        $formToSubmit.submit();
    }
    

提交回复
热议问题