如何在MVC4中获取此URL [英] How to get this urls in MVC4
问题描述
我需要MVC4中的这类网址。
www.example.com/catagories/man/jeans/index
www .example.com / catagories / man / formalpants / index
我该怎么做?
< blockquote>这取决于你如何访问你的控制器。 MVC使用Routes跟踪URL中的项目,您可以通过几种方式将它们分开。如果你正在使用类别区域,你可以将其他元素作为参数传递。
假设类别是区域,man是ManController(kinky)和牛仔裤/正式服装是参数,您可以将以下内容放入Area routeconfig:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection路由)
{
routes.MapRoute(
类别,
categories / {controller} / {type} / {action}
new {controller = man ,action =索引 ,type ='jeans'});
}
}
MVC将自动解析控制器和操作元素。
如果您需要更多信息,请查看:
https://msdn.microsoft.com/en-us/library/cc668201.aspx [ ^ ]
I need this types of urls in MVC4.
www.example.com/catagories/man/jeans/index
www.example.com/catagories/man/formalpants/index
How can I do this??
This depends some on how you're accessing your controllers. MVC uses Routes to track the items in a URL, and you can separate them out in a few ways. If you're using a categories area, you could pass the other elements as arguments.
Assuming categories is an Area, man is ManController (kinky) and jeans/formalpants are arguments, you could put the following into the Area routeconfig:
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "Categories", "categories/{controller}/{type}/{action} new { controller = "Man", action = "Index", type = 'jeans' }); } }
MVC will automatically resolve the controller and action elements.
If you need more information, have a look at:
https://msdn.microsoft.com/en-us/library/cc668201.aspx[^]
这篇关于如何在MVC4中获取此URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!