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

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

问题描述

我用MVC3助手来生成我的Ajax的形式是这样的:

I use The MVC3 Helper to generate my Ajax form like this:

@using (Ajax.BeginForm("Attended", "Lesson", new AjaxOptions
               {
                   HttpMethod = "GET",
                   InsertionMode = InsertionMode.InsertAfter,
                   UpdateTargetId = "mdl" + item.ID
               }))
            {
                @Html.HiddenFor(modelItem => item.ID);
                @Html.CheckBox("Attended", item.Attended, new { OnChange = "javascript:this.form.submit()"});
            }

我只是没有找到合适的方式提交表单上的复选框的更改事件。 我不希望我的用户点击提交按钮。

I just don't find the proper way to submit the Form on the change event of the checkbox. I don't want my users to click the submit button.

在HTMLAttribute工作,但就变回发发生的Ajax请求,而不是。

The HTMLAttribute works, but on the change a postback happens instead of an ajax request.

是否有人知道答案?

推荐答案

首先,创建一个表单里面的提交按钮,并通过设置属性风格=隐藏显示:无;。然后,而不是使用 this.form.submit()在你的onchange事件,使用以下命令:

First, create a submit button inside your form, and hide it by setting the attribute style="display:none;". Then, instead of using this.form.submit() in your onchange event, use the following:

$(this).parents('form:first').find(':submit')[0].click();

这将调用jquery.unobtrusive-ajax.js脚本,并完成您的Ajax提交。

This will invoke the jquery.unobtrusive-ajax.js script, and complete your Ajax submission.

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

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