Ways to define an ASP.NET MVC Route

旧巷老猫 提交于 2019-12-02 02:18:55

问题


I was wondering if you could show me all the various ways to declare routes in ASP.NET MVC (1 and 2). Please explain each method of defining a route, how it is used, and what case it covers.

Here is an example of what I am hoping to collect here:

routes.MapRoute("Directors",
    "Directors/{filter}/{skip}",
    new { controller = "Directors", action = "Index", skip = 0, filter = "" },
    new { skip = @"\d+", filter = @"^[a-zA-Z]+.+" });

Directors = the name of the route. Directors/{filter}/{skip} = the url definition. new { controller = "Directors", action = "Index", skip = 0, filter = "" } = the default for this route. new { skip = @"\d+", filter = @"^[a-zA-Z]+.+" } = the constraints for this route.


回答1:


My first port of call would be the ASP.NET learning pages on routing.

I think this may also be a good use of the Community Wiki feature, as the question you're asking a pretty vague question where there are not real answers, just good documentation on routes.



来源:https://stackoverflow.com/questions/1382473/ways-to-define-an-asp-net-mvc-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!