在Razor MVC中更改URL中的GET参数

在Razor MVC中更改URL中的GET参数,url,razor,asp.net-mvc-4,Url,Razor,Asp.net Mvc 4,我正在ASP.NETMVC4中构建一个分页脚本,我希望能够获取页面的当前URL /Cards/Search?Page=&Terms=&Display=false 并更改页面参数的值。我该怎么做?建议您检查一下RouetConfig是如何工作的。 从这里开始global.asax protected void Application_Start() { AreaRegistration.RegisterAllAreas(); We

我正在ASP.NETMVC4中构建一个分页脚本,我希望能够获取页面的当前URL

 /Cards/Search?Page=&Terms=&Display=false

并更改页面参数的值。我该怎么做?

建议您检查一下RouetConfig是如何工作的。

从这里开始global.asax

  protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes); // Research this
        BundleConfig.RegisterBundles(BundleTable.Bundles);
没有什么可以阻止您调用控制器操作。 你也可以重定向到那里

RedirectToAction("Action","controller");
或者直接重定向

Redirect(myHackedUrl);
如果这是一个更具体的永久网规则,那么在IIS级别还有一个非常有用的工具用于管理重定向。

这可能不是最有效的方法,但它确实适用于我正在做的事情:

RouteValueDictionary rvd = new RouteValueDictionary();
foreach(string item in Request.QueryString){
    if (item != "Page") { rvd.Add(item, Request[item]); }
} 
rvd.Add("Page", 1);

Url.Action("Action", rvd)

我不是试图重定向到其他控制器,而是试图更改GET参数的值。