views:

51

answers:

1

Hi folks,

is it possible to add a dot format / .format to the end of any route in ASP.NET MVC .. with a default being html or something?

and of course the .format is an optional value.

sample routes:-

http://whatever/controller/action.format
http://whatever/controller/action

those goto the same action method.

cheers!

+1  A: 

I'm pretty sure the only clean way to do this would be with two route definitions:

routes.MapRoute(
    "Default",
    "{controller}/{action}.{format}",
    new { controller = "Home", action = "Index", format = "" }
);

routes.MapRoute(
    "Default2",
    "{controller}/{action}",
    new { controller = "Home", action = "Index" }
);

Make sure you maintain the same order in your route definition list as the "Default2" route will override the "Default" route in all cases if placed before it.

Nathan Taylor