简体   繁体   English

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

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

Currently when I make a redirect to action of controller with parameters I have to make like this: 目前,当我使用参数重定向到控制器的动作时,我必须这样做:

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

But Really I woud like that was like this: 但真的我觉得像这样:

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

Why ?? 为什么? Because I thing that looks fine and second is more oriented to route pattern of ASP MVC 因为看起来好的东西所以第2次更加面向ASP MVC的路线模式

Its posible ??? 它的可能性???

PD: Im using knockout js ... PD:我正在使用淘汰赛......

If your server code is ASP.NET MVC then you probably already have RouteConfig.cs: You could use RouteConfig.cs and define your route: Normally you would define a RouteConfig class and under 如果您的服务器代码是ASP.NET MVC,那么您可能已经有了RouteConfig.cs:您可以使用RouteConfig.cs并定义您的路由:通常您将定义一个RouteConfig类并在

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

If hosting on IIS version > 6.0, you could use URL Rewrite 2.0 if your hosting the site on IIS and define the routing rule in IIS for that site. 如果在IIS版本> 6.0上托管,如果您在IIS上托管该站点并在IIS中为该站点定义路由规则,则可以使用URL Rewrite 2.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM