mvc url rewriting
so write now my Url looks like domain.com\MyAction?var1=x&var2=y&var3=z.
Now, in order to make it more seo and user friendly, I want to abandon that way of writing and adopt this kind of url - doman.com\MyAction\x\y\z (obviously order matters now, whic开发者_如何学编程h didn't matter in the previous url)
What is the best way to do this?
Currently:
return RedirectToAction("MyAction", new {var1 = x, var2= y, var3= z});
redirects the page to domain.com\x?var1=y&var2=z&var3=t.
What all needs to be done from this point on... ?
Add a route entry with all those parameters (check your global.asax):
routes.MapRoute(
"MyAction",
"MyAction/{x}/{y}/{z}",
new
{
controller = "yourcontrollerhere",
action = "MyAction"
//default values if the parameters are optional:
//,x = UrlParameter.Optional
});
i would check out the asp.net mvc roxio book by scott gu and scott hanselman the first chapter on the nerd dinner demo is free and believe it covers url routing aspworkshops.com also is a good resource for mvc stuff its by stephen wather who wrote the sams unleashed book on mvc
Try with something like this:
var route = new System.Web.Routing.RouteValueDictionary();
route.Add("var1", "x");
route.Add("var2", "x");
route.Add("var3", "x");
return RedirectToAction("MyAction", route);
精彩评论