MVC3提交的Ajax表单 [英] MVC3 Submit Ajax Form

查看:95
本文介绍了MVC3提交的Ajax表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过许多不同的职位对这个话题,我会继续这样做,并尝试不同的东西。还有,虽然中的信息这么多的变化,我用MVC相对缺乏经验,等等,我觉得我转圈圈了一下。

I've read lots of different posts on this topic and I will continue to do so and try various things. There's so much variation in the information though that, with my relative inexperience with MVC, etc, I feel like I'm going round in circles a bit.

这里的情况。我显示(剃刀)鉴于在MVC3应用程序,包含一个jqGrid的记录。双击打开记录在一个jQuery用户界面对话框记录。原来的观点仅​​包含那些重新presents对话框。调用的动作返回的部分观点,即成为对话DIV的内容。

Here's the situation. I am displaying a (Razor) view in an MVC3 app that contains records in a jqGrid. Double-clicking a record opens that record in a jQuery UI dialog. The original view contains just the that represents the dialog. The invoked action returns a partial view that becomes the content for the dialogue div.

function editItem(gridID, url) {
    var rowID = getSelectedRowID(gridID);

    if (rowID == null) {
        alert('No row selected.\r\nPlease select a row and try again.');
        return;
    }
    else {
        var grid = getGrid(gridID);

        $("#editDialogue").load(url + "/" + grid.SelectedRowID, function (html) {
            $("#editDialogue")[0].value = html;
            $("#editTabs").tabs();
            $("#editDialogue").dialog("open");
        });
    }
}

这部分作品,但我有一种感觉,它可以站在清理了一点点。我真正的问题将在稍后提交包含在该对话框的形式。它应该回发到具有相同的名称,它确实的行动。这一行动被认为验证和保存或返回验证错误相同的局部视图。目前,我想只返回视图,而不做其他事情。该视图被返回,而不是对话的内容之外好吗但整个页面被替换,

That part works, although I have a feeling it could stand a little bit of cleanup. My real issue is later submitting the form contained in that dialog. It's supposed to post back to an action with the same name, which it does. That action is supposed to validate and save or return the same partial view with validation errors. At the moment I'm trying to just return the view without doing anything else. The view is returned alright but the entire page is replaced, instead of just the contents of the dialog.

我已经试过各种事情,包括使用Ajax.BeginForm并指定对话框的div作为AjaxOptions的UpdateTargetId的ID。没有什么迄今的工作。请注意,提交表单的DIV中,因此将被替换了。不知道这是问题的一部分。

I've tried various things, including using Ajax.BeginForm and specifying the id of the dialog div as the UpdateTargetId of the AjaxOptions. Nothing has worked so far. Note that the form being submitted is inside the div so it will be replaced too. Not sure if this is part of the problem.

我收拾了一天,所以我现在想我会后,看到一夜,早上再次攻击问题之前发生了什么。

I'm packing up for the day now so I thought I'd post and see what happens overnight before attacking the problem again in the morning.

推荐答案

jmcilhinney, 你是对的设置AjaxOptions.UpdateTargetId,但你还需要设置AjaxOptions.InsertionMode为InsertionMode.Replace。

jmcilhinney, You were right to set the AjaxOptions.UpdateTargetId, but you also need to set AjaxOptions.InsertionMode to InsertionMode.Replace.

这篇关于MVC3提交的Ajax表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆