Jquery MVC2页面导航 - 如何在服务器上获取正确的URL

时间:2011-08-22 21:02:46

标签: jquery asp.net-mvc-2

在我编写的MVC2应用程序中,我发现无法使用jquery ajax调用导航到正确的操作和控制器(我实际上是尝试使用对操作方法的ajax调用来填充下拉列表) 。它适用于我的Visual Studio开发盒,但在服务器上,我遇到了问题。其中一个是当我点击提交按钮时,肯定没有找到控制器动作的正确路径?有没有办法可以使用DOM来获取我的动作和控制器的正确路径?现在,我正在使用目标ID的'action'属性(我猜这是指我所做的链接 - 不确定)尝试导航到正确的操作......但这不起作用。我试图导航到'Controller / Action'而不是'server / location / Controller / Action'是一般的。请查看我的代码并查看...

     $("#btnSubmit").live('click', function (event) {
        event.preventDefault();
        var $target = $(this).attr("name");
        var $url = $("#target").attr("action");
        $.ajax({
            url: $url,
            type: 'POST',
            data: $("#target").serialize(),
            success: function (response) {
                $.simpleDialog.close();
                $($target).html(response);
                $("#ajaxResult").hide().html('Record saved.').fadeIn(300, function () {
                    var e = this;
                    setTimeout(function () { $(e).fadeOut(400); }, 2000);
                });
            },
            error: function (xhr, status) {
                $("#ajaxResult").html(xhr.responseText).show();
                $.simpleDialog.close();
            }
        });
    });

你会推荐什么?感谢。

德里克

0 个答案:

没有答案