ASP.NET MVC Routing with Default Controller

前端 未结 3 598
清酒与你
清酒与你 2020-12-08 08:10

For a scenario, I have a ASP.NET MVC application with URLs that look like the following:

http://example.com/Customer/List
http://example.com/Customer/List/Pa         


        
3条回答
  •  眼角桃花
    2020-12-08 08:50

    don't mix a rule like: "{action}/{id}" with one that's "{controller}/{action}/{id}" ... specially when id in the later has a default value i.e. is optional.

    In that case you have nothing that allows routing to know which one is the right one to use.

    A workaround, if that's what you need, would be to add a constrain (see this) to the action in the earlier to a set of values i.e. List, View. Of course that with these types of rules, you can't have a controller with the same name of an action.

    Also remember that if you specify a default action & id in the "{action}/{id}" rule, that will be used when you hit the route of your site.

提交回复
热议问题