开发者

MVC form hijaxing

I have a Controller that returns either a PartialView or a RedirectToAction result wh开发者_开发百科en doing an ajax request.

Now the problem is that in the View I want to either display the PartialView or Rediect to the Action depending on what the Controller returns, but I can't think of a way of differentiating the response of the Controller...

Here's my code. This works fine when a PartialView is returned by the Controller, but it displays the content of the RedirectToAction too if that was what the Controller returned:

$(".Form").live("submit", function () {
    $.updateForm(this, "#CodeForm");
    return false;
});

$.updateForm = function (myv, divToUpdate) {
    $.post($(myv).attr("action"),
        $(myv).serialize(),
        function (data) {
            //alert("Data Loaded: " + data);
            $(divToUpdate).slideUp("normal", function () {
                $(divToUpdate).html(data).slideDown("slow", "");
            });
        });

}


When you get the data , check if it has a <body> tag, if it doesn't, it was a PartialView, otherwise it was a normal view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜