在模态对话框MVC、jQuery中提交部分视图表单

Submitting a partial view form within a modal dialog MVC, jQuery

本文关键字:提交部 视图 表单 jQuery 模态 对话框 MVC      更新时间:2023-09-26

这是我的代码:

<td class="tedit">
                    <%= Html.ActionLink(item.Comments, "Comments", new { jobNumber = item.JobNumber, ordNumber = item.OrderNumber }, new { @class = "modalEdit" })%>
 </td>

<div id="resultEdit" title="Edit Comments" style="display: none;">
       <% Html.RenderPartial("AddComments", Model.InnerModel.RoadReportModelProp); %>
</div>

 <script type="text/javascript">
        $(document).ready(function () {
            //initialize the dialog
            $("#resultEdit").dialog({ modal: true, width: 300, resizable: true, position: 'center', title: 'Add Comments', autoOpen: false,
                buttons: { "Save": function () {
                    var dlg = $(this);
                    dlg.Close();
                   }}
        });
                        });
        $(function () {
            $('.modalEdit').click(function () {
                //load the content from this.href, then turn it into a dialog.
                $('#resultEdit').load(this.href).dialog('open');
                $.unblockUI();
                return false;
            });
        });
      </script>

当我点击对话框中的SAVE按钮时,我需要向控制器发送POST请求,但我无法发送POST。

请帮忙。

您应该能够使用$.post来保存数据。例如

$.post(url, data, function(response) {
    // Do something with response
});

您需要从对话框中收集数据。

问候,

Huske

  <div> 
        <% using (Html.BeginForm("Post-FormActionName", "Controllername"))
           {
        %>             
             <div class="fieldsColumn">
              <label>Name: *</label>
                <%=Html.TextBoxFor("Name")%>
        </div>
            <div class="fieldsColumn">
              <input id="submit" type="submit" value="Save"/>
        </div>

        <%}%>      
</div>

您可以使用以下内容来发布,此外,您是否可以提供要发布的表单的代码,&还有您创建的控制器:

<script type="text/javascript">
$(document).ready(function() {
    //get the form
    var f = $("#idofForm");
    var action = f.attr("action");
    var serializedForm = f.serialize();
    $.post(action, serializedForm, function() {
        alert('we are back');
    }
});
</script>