Window.location在ajax调用成功后无法正常工作

时间:2015-04-03 19:26:43

标签: jquery ajax asp.net-mvc asp.net-ajax

我的路线 -

    routes.MapRoute(
     name: "SupplyChainPressureSocialResults",
     url: "supply-chain-pressure/results/{id}",
     defaults: new { controller = "SupplyChainPressure", action = "Results" }
     );

控制器方法 -

//GET:/supply-chain-pressure/ScptResult/{id}
public ActionResult ScptResult(int resultid)
{
   // do something
    return View();
}

ajax cal -

$.ajax({
                    type: "POST",
                    url: configMap.sitePath + "api/Quiz/" + quizResponse.quizId,
                    data: JSON.stringify(quizResponse),
                    success: function (data) {
                        window.location.href = configMap.sitePath + 'supply-chain-pressure/ScptResult' + data.data.quizInstanceID;
                    },

但由于某种原因,重定向没有发生。有人可以帮忙吗

2 个答案:

答案 0 :(得分:0)

您重定向到的地点与您的路线不符。您的路线正在寻找: supply-chain-pressure/results/{id}

但您正在重定向到:

supply-chain-pressure/ScptResult/{id}

您的路线永远不会匹配,因为您传递的是ScptResult而不是results

您要做的是将路线定义更改为:

routes.MapRoute(
name: "SupplyChainPressureSocialResults",
url: "supply-chain-pressure/{action}/{id}",
defaults: new { controller = "SupplyChainPressure", action = "results" }
);

答案 1 :(得分:0)

问题缺失/

应该是 -

 window.location.href = configMap.sitePath + 'supply-chain-pressure/ScptResult/' + data.data.quizInstanceID;

我错过了' /'最后。