返回带参数的视图

时间:2012-10-05 07:52:33

标签: javascript ajax asp.net-mvc

基本上我有MVC网站,我的页面上有很少的标签,使用JavaScript。

然后我有JavaScript方法读取此URL并使用AJAX选择适当的选项卡,如下所示:

function onbodyLoad(URL) {

    if (URL.indexOf("Login/Register") != -1) {
        var index = 4;
        var $tabs = $('#tabs').tabs();
        $tabs.tabs('url', index, "/Login/RegistrationConfirmation");
        $tabs.tabs('select', index + 1); 
        $tabs.tabs('select', index); 
    }
}

现在我在控制器的httppost方法中检查null的几个属性并返回一个视图。它有效,但风格缺失,所以必须按照上述方式进行。

如果没有错误,它是否可以写入页面URL“Success”,如果它们为null,则写入url“Error”。所以在上面的函数中我可以检查URL并转发到适当的选项卡。

或者也许用参数写一个actionresult方法并返回它。但是不知道......任何人都可以解决一些问题

希望它有意义。


更新 在我的控制器上,我这样做是为了在我的寄存器视图中添加参数:

RouteValueDictionary rvd = new RouteValueDictionary();
rvd.Add("ParamID", "1");
return RedirectToAction("Register", "Login", rvd);

和Jquery我这样做是为了阅读网址并选择该标签:

if (URL.indexOf("Login/Register?ParamID=1") != -1) {
    var index = 2;
    var $tabs = $('#tabs').tabs(); 
    $tabs.tabs('url', index, "/Login/Register");
    $tabs.tabs('select', index + 1); 
    $tabs.tabs('select', index); 
}

我可以看到带参数的url但jquery似乎不起作用,它只是说无法找到。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

如果查看API,您可以找到用于选项卡初始化的ajaxOptions选项。

$tabs.tabs({ ajaxOptions: { async: false } });

$tabs.tabs({ ajaxOptions: { async: false } });

更合适:

// Definition of the tabs variable, note in particular the argument 'ajaxOptions'
var $tabs = $('#example').tabs({
    ajaxOptions: {
        success: function() {
            $tabs.tabs('select', getIndex() + 1); 
            $tabs.tabs('select', getIndex() );
        },
        error: function() {}
    }
});

function getIndex() {
    return 4;
}

function onbodyLoad(URL) {

    if (URL.indexOf("Login/Register") != -1) {

        var $tabs = $('#tabs').tabs();
        $tabs.tabs('url', index, "/Login/RegistrationConfirmation");
    }
}

这会有帮助吗??

P.S。我没有测试过这个。