我在JavaSctipt中生成一个URL。
我第一次生成此URL时,我得到了正确的URL:
例如。 **http://localhost:54415/NffCall/Details/DK/6607726**
但是下次我生成链接时,我得到了前一个链接和当前参数:
例如。 http://localhost:54415/NffCall/Details/DK/6607726/DK/6608146
生成我的网址的代码如下所示:
var actionUrlBase = '@Url.Action("Details", "NffCall")';
var actionUrl = actionUrlBase + '/' + countryCode + '/' + orderNumber;
window.location.href = actionUrl;
我该怎样做才能每次生成正确的链接?
编辑: 我将粘贴RouteCollection的样子:
routes.MapRoute(
name: "CountryCodeOrderNumberDetails",
url: "{controller}/{action}/{countryCode}/{orderNumber}",
defaults: new { controller = "NffCall", action = "Details", countryCode = (string)null, orderNumber = (int?)null },
constraints: new { countryCode = "[a-zA-Z]{2}", orderNumber = "[0-9]+" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
答案 0 :(得分:2)
请改用Helper @ Url.RouteUrl。
var actionUrlBase = '@Url.RouteUrl("Default",new {action="Details", controller= "NffCall"},Request.Url.Scheme)';
var actionUrl = actionUrlBase + '/' + countryCode + '/' + orderNumber;
window.location.href = actionUrl;