当我在Asp.net核心中使用RedirectToAction时,我的URL链接正在使用URLEnCode

问题描述 投票:0回答:1

当我在我的asp .net核心项目中使用RedirectToAction方法时,My Url链接转到http://localhost:2468/Passage/Details%3FpassageId%3D1它应该是http://localhost:2468/Passage/Details?passageId=1

我该怎么解决呢

_ statisticsAppService.UpNumPlus(passageId); 
return RedirectToAction("Details?passageId = " + passageId,"Passage");
controller asp.net-core-mvc
1个回答
0
投票

您正在使用RedirectToAction方法错误。您应该将路由值作为单独的参数传递,RedirectToAction方法将为您构建查询字符串。

使用this overloadRedirectToAction

protected internal RedirectToRouteResult RedirectToAction(
    string actionName,
    string controllerName,
    object routeValues
)

所以你的代码应该是

int passageId = 1;  // Some passageId value you have
return RedirectToAction("Details","Passage", new { passageId = passageId  });
© www.soinside.com 2019 - 2024. All rights reserved.