【问题标题】:Submitting a partial view form within a modal dialog MVC, jQuery在模态对话框 MVC、jQuery 中提交部分视图表单
【发布时间】:2011-09-21 22:11:59
【问题描述】:

这是我的代码:

<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>

单击对话框中的“保存”按钮时,我需要向控制器发送 POST 请求,但我无法发送 POST。

请帮忙。

【问题讨论】:

  • 我需要在 POST 上将结果保存到数据库中

标签: javascript jquery model-view-controller modal-dialog partial-views


【解决方案1】:

您应该可以使用 $.post 来保存您的数据。例如

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

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

问候,

哈士奇

【讨论】:

    【解决方案2】:
      <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>
    

    【讨论】:

      【解决方案3】:

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

      <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>
      

      【讨论】:

      • " %>
        添加评论:
        这是我的部分视图代码
      猜你喜欢
      • 2011-09-20
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-10
      • 1970-01-01
      • 2011-10-17
      相关资源
      最近更新 更多