James South
James South

Reputation: 10645

MVC Routing Help Required

I'm trying to map the following routes in MVC2.

[absoluteUrl]

[absoluteUrl]/[dynamicBlogName]

These two routes should map to the same controller/actionresult.

e.g PostController/Index

I also need to map these routes.

[absoluteUrl]/post/[dynamicPostName]

[absoluteUrl]/[dynamicBlogName]/post/[dynamicPostName]

These two routes should also map to the same controller/actionresult.

e.g PostController/Default

Any help would be greatly appreciated.

Upvotes: 1

Views: 98

Answers (1)

Christopher Stott
Christopher Stott

Reputation: 1478

I'm not in front of Visual Studio - but try something like this.

routes.MapRoute(
      "Default1",                                   
      "",                           
      new { controller = "PostController", action = "Index", dynamicBlogName = ""} 
);
routes.MapRoute(
      "Default2",                                             
      "{dynamicBlogName}",                          
      new { controller = "PostController", action = "Index", dynamicBlogName = ""  } 
);
routes.MapRoute(
      "Default3",                                         
      "post/{dynamicPostName}",                           
      new { controller = "PostController", action = "Default", dynamicBlogName = "", dynamicPostName="" }
);
routes.MapRoute(
      "Default4",                                            
      "{dynamicBlogName}/post/{dynamicPostName}",            
      new { controller = "PostController", action = "Default", dynamicBlogName = "", dynamicPostName=""  }
);

Upvotes: 1

Related Questions