我可以在ASP.NET MVC中有以下路线:: http://whatever/controller/action.format

问题描述:

是否有可能将dot format/.format添加到ASP.NET MVC中的任何路由的末尾..默认情况下是HTML还是什么?我可以在ASP.NET MVC中有以下路线:: http://whatever/controller/action.format

当然.format是一个可选值。

样品路线: -

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

那些转到相同的操作方法。

干杯!

我敢肯定的只有干净的方式做这将是两个路由定义:

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

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

确保你在你的路由定义列表保持相同的顺序为“默认设置2”的路线将覆盖所有情况下的“默认”路线如果放置在它之前。