通过 JavaScript 使用参数 (ASP.NET MVC) 重定向到动作控制器

Redirect to action controller by JavaScript with parameters (ASP.NET MVC)

目前,当我使用参数重定向到控制器的操作时,我必须这样做:

window.location.href = "/Controller/Action/?parameterId=" + this.Id();

但我真的希望是这样的:

window.location.href = "/Controller/Action/" + this.Id();

为什么??因为我看起来不错,第二个更面向 ASP MVC

的路由模式

有可能吗???

PD:我正在使用 knockout js ...

如果您的服务器代码是 ASP.NET MVC,那么您可能已经拥有 RouteConfig.cs: 您可以使用 RouteConfig.cs 并定义您的路线: 通常你会定义一个 RouteConfig class and under

public static void RegisterRoutes(RouteCollection routes){
routes.MapRoute("myRoute","AreaName", new {controller="ControllerName", 
action="ActionName",id=UrlParameter.Optional});
}

如果在 IIS 版本 > 6.0 上托管,您可以使用 URL Rewrite 2.0 如果您在 IIS 上托管网站并在 IIS 中为该网站定义路由规则。