Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法重载Ajax.BeginForm的提交方法_Javascript_Jquery_Ajax_Asp.net Mvc 3_Razor - Fatal编程技术网

Javascript 无法重载Ajax.BeginForm的提交方法

Javascript 无法重载Ajax.BeginForm的提交方法,javascript,jquery,ajax,asp.net-mvc-3,razor,Javascript,Jquery,Ajax,Asp.net Mvc 3,Razor,我试图从razor视图提交一个ajax表单,我希望控制器返回一个JSON对象。当我使用(“#form0”).submit(提醒(“hi”);数据进入控制器,我得到一个警报。但是,当我使用(“#form0”).submit(函数(){alert(“hi”);});数据没有传递,我也没有收到警报。我觉得这是我语法中的一个小错误,我没有。以下是相关代码: jquery: $(function () { //setting up the schedule modal dialoag. $("#sched

我试图从razor视图提交一个ajax表单,我希望控制器返回一个JSON对象。当我使用(“#form0”).submit(提醒(“hi”);数据进入控制器,我得到一个警报。但是,当我使用(“#form0”).submit(函数(){alert(“hi”);});数据没有传递,我也没有收到警报。我觉得这是我语法中的一个小错误,我没有。以下是相关代码:

jquery:

$(function () {
//setting up the schedule modal dialoag.
$("#schedModal").dialog({
    buttons: {
        Submit:
                function () {
                    $("#form0").ajaxSubmit(function () {
                        //this is where I want to put the magic, but I need the alert to fire first.
                        alert("hi");
                        return false;
                    });
                },
        Cancel:
                function () {
                    $(this).dialog("close");
                }
    },
    autoOpen: false,
    minHeight: 350,
    modal: true,
    resizable: false
});
目标视图:

@model FSDS.DataModels.Schedule

@using (Ajax.BeginForm("scheduleNew", null, new AjaxOptions { UpdateTargetId = "partial" }, new {}))
{
@Html.ValidationSummary(true)

    <div class="editor-label">
        @Html.LabelFor(model => model.ScheduleName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ScheduleName)
        @Html.ValidationMessageFor(model => model.ScheduleName)
    </div>

    @* tons of other labels and editor fields go in here, omitted for brevity. *@
}
只需使用
$('#form0').submit()

然后在AjaxForm中定义一个
OnSuccess
处理程序,当AJAX请求成功时将调用该处理程序:

@using (Ajax.BeginForm("scheduleNew", null, new AjaxOptions { OnSuccess = "success", UpdateTargetId = "partial" }, new {}))
最后是
success
javascript处理程序:

function success(data) {
    // the form was successfully submitted using an AJAX call.
    // here you could test whether the data parameter
    // represents a JSON object or a partial view
    if (data.ScheduleName) {
        // the controller action returned the schedule JSON object
        // => act accordingly
    } else {
        // the controller action returned a partial view
        // => act accordingly
    }
}

像做梦一样工作。你是一位绅士和学者,达林·迪米特洛夫。
@using (Ajax.BeginForm("scheduleNew", null, new AjaxOptions { OnSuccess = "success", UpdateTargetId = "partial" }, new {}))
function success(data) {
    // the form was successfully submitted using an AJAX call.
    // here you could test whether the data parameter
    // represents a JSON object or a partial view
    if (data.ScheduleName) {
        // the controller action returned the schedule JSON object
        // => act accordingly
    } else {
        // the controller action returned a partial view
        // => act accordingly
    }
}