redirecttoroute

How to use RedirectToRoute(“routeName”) in MVC?

你。 提交于 2019-12-10 18:47:03
问题 I am just puzzled on why is my RedirectToRoute() method not working. I have a RouteConfig.cs file like this routes.MapRoute( "pattern1", "{action}", new { controller = "Home", action = "About" } ); routes.MapRoute( "pattern2", "{controller}/{action}/{id}", new { controller = "Admin", action = "Index", id = UrlParameter.Optional } ); on this configuration my default controller Home and action About is getting called, now in the action method I am calling RedirectToRoute() with the following

Passing querystrings to RedirectToRouteResult (beside controller and action)

江枫思渺然 提交于 2019-12-01 02:36:25
I have the following code: var routeDictionary = new RouteValueDictionary {{"action", "Login"}, {"controller", "Persons"}}; filterContext.Result = new RedirectToRouteResult(routeDictionary); That will produce " /Persons/Login " How can I pass an aditional querystring to the previous code? so that it produces " /Persons/Login/?someQuerystring=someValue " Try this: filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "action", "login" }, { "controller", "persons" }, { "someQuerystring", "someValue" } } ); 来源: https://stackoverflow.com/questions/17150647/passing

Passing querystrings to RedirectToRouteResult (beside controller and action)

谁都会走 提交于 2019-11-30 22:12:29
问题 I have the following code: var routeDictionary = new RouteValueDictionary {{"action", "Login"}, {"controller", "Persons"}}; filterContext.Result = new RedirectToRouteResult(routeDictionary); That will produce " /Persons/Login " How can I pass an aditional querystring to the previous code? so that it produces " /Persons/Login/?someQuerystring=someValue " 回答1: Try this: filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "action", "login" }, { "controller", "persons"

How is RedirectToRoute supposed to be used?

六眼飞鱼酱① 提交于 2019-11-28 10:39:51
I have this in my Global.asax.cs: routes.MapRoute("BetaAccess", "beta-access", new { controller = "Beta", action = "Index" }); And this in my controller (index action on HomeController) and it definitely is getting hit: RedirectToRoute("BetaAccess"); But still no redirection happens... it just goes to the normal home page. Am I using it wrong? Also, I can do Response.Redirect("~/beta-access") and it goes to the beta page... RedirectToRoute returns a RedirectToRouteResult. Try this instead. return RedirectToRoute("BetaAccess"); This will redirect you. Response.RedirectToRoute("BetaAccess");

How is RedirectToRoute supposed to be used?

我们两清 提交于 2019-11-27 03:43:05
问题 I have this in my Global.asax.cs: routes.MapRoute("BetaAccess", "beta-access", new { controller = "Beta", action = "Index" }); And this in my controller (index action on HomeController) and it definitely is getting hit: RedirectToRoute("BetaAccess"); But still no redirection happens... it just goes to the normal home page. Am I using it wrong? Also, I can do Response.Redirect("~/beta-access") and it goes to the beta page... 回答1: RedirectToRoute returns a RedirectToRouteResult. Try this