如何在mvc中提交按钮点击事件之前调用Beginform提交方法?

时间:2015-02-03 05:44:51

标签: javascript asp.net-mvc-3 asp.net-mvc-4 onsubmit html.beginform

我在控制器中使用BeginForm()方法有一个表单提交方法,但在同一方法中,我还在_Layout.cshtml页面上的提交按钮上有点击事件。目前,第一次点击事件被触发,然后调用BeginForm()方法。

那么,如何在提交按钮点击事件之前先调用BeginForm()方法?

提交按钮点击事件:(_Layout.cshtml

$("#SaveData").click(function (b) {
    debugger

    var list = new Array();
    var postData;

    $('input.chkevent').each(function () {
        debugger

        if (this.checked == true) {

            var parent_id = this.parentElement;
            var par2 = parent_id.previousElementSibling;
            var par3 = par2.previousElementSibling;
            var child = par3.childNodes[0];
            var child_val = child.defaultValue;

            var arr_date = this.parentElement.nextElementSibling.childNodes[0].value;
            var dep_date = this.parentElement.nextElementSibling.nextElementSibling.childNodes[0].value;
            var id = new Array(); ;
            id.push(child_val, arr_date, dep_date);
            list.push(id);
            postData = { values: list};
        }
    });


$.ajax({
        url: '@Url.Action("FormData", "HomeSurface")',
        //jQuery.ajaxSettings.traditional = true
        //  url: "CheckEvent/PersonEvent?id=" + allVals,
        data: postData,
        type: "POST",
        traditional: true,
        // dataType: "json",
        // traditional: true,
        success: function () {
        }
    });
});

Submit_Form(Index.cshtml):

 @using (Html.BeginUmbracoForm<HomeSurfaceController>("FormData"))
 {
     <fieldset>
     </fieldset>
 }

在控制器中:

 public ActionResult FormData(PERSON_MASTER person, string[] values)
 {

 }

0 个答案:

没有答案