views:

49

answers:

3

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, which 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... ?

A: 

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

Chris McGrath
A: 

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);
Hector
A: 

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
   });
eglasius
"MyAction/{x}/{y}/{z}", but how do I make z optional when x and y are filled out and y optional when x is filled out...
progtick
eglasius
actually, never mind. I didn't explain my question well.
progtick