开发者

how to redirect to a Url with a parameter from an asp.net-mvc controller

i have an asp.net-mvc site and one of the pages is

http://www.mysite.com/Report

users can add client side filtering which generates urls like 开发者_开发技巧this:

http://www.mysite.com/Report?Region=US

i want to take a link like this:

http://www.mysite.com/MyLastReport

and have a controller action that mimics as if a person added some parameters to the URL like this:

http://www.mysite.com/Report?Region=US

as my server side code uses:

 Request.Params[]

to filter my queries and i want to use the same code path to get the results as if the URL had these parameters on the client side.

also, is there anyway to literally do a redirect of the URL from the server side so i actually change the URL in the browser to:

http://www.mysite.com/Report?Region=US


Add the following to the Global.asax:

protected void OnBeginRequest(object sender, EventArgs e)
{
    if (Request.Url.AbsolutePath.Equals("/MyLastReport", StringComparison.OrdinalIgnoreCase)) {
        Context.RewritePath("/Report?Region=US");
    }
}

public override void Init()
{
    base.Init();
    BeginRequest += OnBeginRequest;
}

UPDATE: From controller action you can use RedirectToAction method:

RedirectToAction("ReportActionName", new { Region = "US" });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜