ASP.NET - Ajax.BeginForm的onSuccess回调与PARAMS [英] ASP.NET - Ajax.BeginForm OnSuccess call back with params

查看:177
本文介绍了ASP.NET - Ajax.BeginForm的onSuccess回调与PARAMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加更多的PARAMS我的onSuccess回调(,但保留AJAX环境变量)。
我所做的是:

I want to add more params to my OnSuccess call back (but keep the ajax context variable).
What I did is:

 using (Ajax.BeginForm("Register", new AjaxOptions() {
   OnSuccess = "new function(arg){HandleBasicForm(arg , 'MyCustomVariable')}",
    ...

JS的功能:

The JS function:

function HandleBasicForm(ajaxContext , myCustomVariable){
            var content = ajaxContext.get_response().get_object();
            ....
        }

ajaxContext 为null。
我该怎么办呢?

But ajaxContext is null.
How do I do that?

推荐答案

由于您使用 get_response()我猜你不使用不显眼JavaScript的东西(在MVC3你设置 HtmlHelper.UnobtrusiveJavaScriptEnabled = FALSE ),你就引用MicrosoftAjax,js和MicrosoftMvcAjax.js文件。如果是这样的话,你只需要删除关键字。

Since you're using get_response() I'm guessing that you're not using the unobtrusive javascript stuff (in MVC3 you've set HtmlHelper.UnobtrusiveJavaScriptEnabled = false) and you're referencing the MicrosoftAjax,js and MicrosoftMvcAjax.js files. If that's the case you just need to drop the new keyword.

 using (Ajax.BeginForm("Register", new AjaxOptions() {
   OnSuccess = "function(arg){HandleBasicForm(arg , 'MyCustomVariable')}"})

如果您使用的是带有jquery.unobtrusive-ajax.js的MVC3不显眼的JavaScript的支持,那么你可以使用隐式可用 XHR 数据变量来代替。

If you are using the MVC3 unobtrusive javascript support with jquery.unobtrusive-ajax.js then you can use the implicitly available xhr and data variables instead.

using (Ajax.BeginForm("Register", new AjaxOptions() {
       OnSuccess = "HandleBasicForm(data, 'MyCustomVariable')"})

在你的处理器就没有必要使用 get_response()的get_object(),因为反序列化的JSON数据将在直接处理程序被通过。

In your handler there would be no need to use get_response().get_object() since the deserialized JSON data would be passed in to your handler directly.

function HandleBasicForm(data, myCustomVariable){
            var someValue = data.someProperty; //work with data object returned
            ....
        }

这篇关于ASP.NET - Ajax.BeginForm的onSuccess回调与PARAMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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