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

发布于 2024-11-17 00:20:57 字数 1269 浏览 1 评论 0原文

这是我的代码:

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

请帮忙。

Here is my code:

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

I need to send a POST request to the controller when I click on the SAVE button in the dialog, but I am not able to send a POST.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吻安 2024-11-24 00:20:57

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

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

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

问候,

哈斯克

You should be able to use $.post to save your data. For example

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

You will need to collect the data from the dialog.

Regards,

Huske

时光无声 2024-11-24 00:20:57
  <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>
  <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>
悟红尘 2024-11-24 00:20:57

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

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

You can use the following to Post, further, can you provide the code for the form you want to post, & also the controller you have created:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文