Window.location中成功调用ajax中不工作

Window.location in the sucess of the ajax call is not working

我的路线 -

    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 校准 -

$.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;
                    },

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

您重定向到的地方与您的路线不匹配。您的路线正在寻找: 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" }
);

缺少问题/

应该是 -

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

我漏掉了末尾的“/”。