Can i have the following route in ASP.NET MVC :: http://whatever/controller/action.format
is it possi开发者_运维百科ble 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!
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.
精彩评论