Javascript 未使用ajax从Jquery对话框调用控制器post操作

Javascript 未使用ajax从Jquery对话框调用控制器post操作,javascript,jquery,ajax,asp.net-mvc-4,Javascript,Jquery,Ajax,Asp.net Mvc 4,我试图使用ajax从jquery对话框调用控制器的后期操作方法,但无法做到这一点。我确信有一些非常小的东西,但即使在多次检查我的代码后也找不到任何东西。有人能帮我找出这个问题吗 在我看来,Javascript: $('a.actionLinkAttentionButton').click(function () { var url = $(this).attr('href'); var dialogDiv = $('<div id="succ

我试图使用ajax从jquery对话框调用控制器的后期操作方法,但无法做到这一点。我确信有一些非常小的东西,但即使在多次检查我的代码后也找不到任何东西。有人能帮我找出这个问题吗

在我看来,Javascript:

$('a.actionLinkAttentionButton').click(function () {
            var url = $(this).attr('href');
            var dialogDiv = $('<div id="success" style="display:none;background-color:#efeeef;"></div>').appendTo('body');
            dialogDiv.load(url, {},
                function (responseText, textStatus, XMLHttpRequest) {
                    dialogDiv.dialog({
                        title: "Resolve log issue",
                        close: function (event, ui) {
                            dialogDiv.remove();
                        },
                        width: 600,
                        show: { effect: "blind", duration: 400 },
                        hide: { effect: "blind", duration: 500 },
                        modal: { backdrop: 'static', keyboard: false },
                        buttons: {
                            "Save": function () {
                                $.ajax({
                                    url: '@Url.Action("ResolveLogPost","Attendance")',
                                    type: "POST",
                                    async: false,
                                    data: $('ResolveLogForm', $(this)).serialize()
                                });
                            },
                            "Close": function () {
                                $(this).dialog('close');
                            },
                        },
                        success: function (response) {
                            dialogDiv.dialog('close');
                        },
                        dialogClass: 'no-close success-dialog'
                    });
                });
            return false;
        });
局部视图:

@using (Html.BeginForm("ResolveLogPost", "Attendance", FormMethod.Post, new { enctype = "multipart/form-data", @id = "ResolveLogForm" }))
{
    @Html.AntiForgeryToken()

    <fieldset>
        <legend>BiometricLogAction</legend>

        <table class="ListTable" style="width:100%">
            @Html.HiddenFor(model => model.EmployeeCode)
            @Html.HiddenFor(model => model.date)
            <tr><td colspan="2" style="background-color:#a6c100;color:white">@Html.Label("Log Details")</td></tr>
            <tr>
                <td style="width:200px;">@Html.LabelFor(model => model.LogDate)</td>
                <td>@Html.DisplayFor(model => model.LogDate)</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.FinalInTime)</td>
                <td>@Html.DisplayFor(model => model.FinalInTime)</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.FinalOutTime)</td>
                <td>@Html.DisplayFor(model => model.FinalOutTime)</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.WorkingTime)</td>
                <td>@Html.DisplayFor(model => model.WorkingTime)</td>
            </tr>
        </table>
        <table>
            <tr>
                <td>@Html.CheckBoxFor(model => model.Accepted, new { @id = "chkprivate" })</td>
                <td>@Html.LabelFor(model => model.Accepted)</td>
            </tr>
        </table>
        <table>
            <tr>
                <td>@Html.LabelFor(model => model.ProofFileName)</td>
                <td>@Html.TextBoxFor(m => m.ProofFileName, new { type="file", name = "file", @id="uploadfile"})</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.Remarks)</td>
                <td>@Html.TextAreaFor(model => model.Remarks, new { style = "width:300px;" })</td>
            </tr>
        </table>
    </fieldset>
}
@使用(Html.BeginForm(“ResolveLogPost”、“attention”、FormMethod.Post、new{enctype=“multipart/formdata”、@id=“ResolveLogForm”}))
{
@Html.AntiForgeryToken()
生物统计作用
@Html.HiddenFor(model=>model.EmployeeCode)
@Html.HiddenFor(model=>model.date)
@标签(“日志详细信息”)
@LabelFor(model=>model.LogDate)
@DisplayFor(model=>model.LogDate)
@LabelFor(model=>model.finalitime)
@DisplayFor(model=>model.FinalInTime)
@LabelFor(model=>model.FinalOutTime)
@DisplayFor(model=>model.FinalOutTime)
@LabelFor(model=>model.WorkingTime)
@DisplayFor(model=>model.WorkingTime)
@CheckBoxFor(model=>model.Accepted,新的{@id=“chkprivate”})
@LabelFor(model=>model.Accepted)
@Html.LabelFor(model=>model.proof文件名)
@Html.TextBoxFor(m=>m.proof文件名,新的{type=“file”,name=“file”,@id=“uploadfile”})
@LabelFor(model=>model.comments)
@Html.TextAreaFor(model=>model.comments,新{style=“width:300px;”})
}

经过几次更改后,它终于可以工作了。虽然,我真的不相信这些是真正的根源,但我仍然很高兴它成功了;)。我做了以下修改:

局部视图:

@using (Html.BeginForm("ResolveLogPost", "Attendance", FormMethod.Post, new { enctype = "multipart/form-data", @id = "ResolveLogForm" }))
{
    @Html.AntiForgeryToken()

    <fieldset>
        <legend>BiometricLogAction</legend>

        <table class="ListTable" style="width:100%">
            @Html.HiddenFor(model => model.EmployeeCode)
            @Html.HiddenFor(model => model.date)
            <tr><td colspan="2" style="background-color:#a6c100;color:white">@Html.Label("Log Details")</td></tr>
            <tr>
                <td style="width:200px;">@Html.LabelFor(model => model.LogDate)</td>
                <td>@Html.DisplayFor(model => model.LogDate)</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.FinalInTime)</td>
                <td>@Html.DisplayFor(model => model.FinalInTime)</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.FinalOutTime)</td>
                <td>@Html.DisplayFor(model => model.FinalOutTime)</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.WorkingTime)</td>
                <td>@Html.DisplayFor(model => model.WorkingTime)</td>
            </tr>
        </table>
        <table>
            <tr>
                <td>@Html.CheckBoxFor(model => model.Accepted, new { @id = "chkprivate" })</td>
                <td>@Html.LabelFor(model => model.Accepted)</td>
            </tr>
        </table>
        <table>
            <tr>
                <td>@Html.LabelFor(model => model.ProofFileName)</td>
                <td>@Html.TextBoxFor(m => m.ProofFileName, new { type="file", name = "file", @id="uploadfile"})</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(model => model.Remarks)</td>
                <td>@Html.TextAreaFor(model => model.Remarks, new { style = "width:300px;" })</td>
            </tr>
        </table>
    </fieldset>
}
  • 添加了空路由值以使用不同的重载
  • 已将enctype更改为@enctype

    @使用(Html.BeginForm(“ResolveLogPost”,“Attention”,null,FormMethod.Post,new{@id=“form”,@enctype=“multipart/form data”}))


  • 您是否可以不使用
    数据:$(“ResolveLogForm”).serialize()
    ?并指定要发送的
    数据类型是什么?(
    json
    )已尝试,但也无法工作对控制器参数使用
    FromBody
    属性如何
    public ActionResult ResolveLogPost([FromBody]BiometricLog model)
    仍然不走运:(好的,用所需参数的名称发送数据怎么样?
    data:{“model”:$('ResolveLogForm',$(this)).serialize()}