使用ASP.NET MVC,我需要像这样配置我的URL:
www.foo.com/company:渲染查看公司
www.foo.com/company/about:渲染查看公司
www.foo.com/company/about/mission:渲染查看任务
如果“公司”是我的控制者而“约”是我的行动,应该是什么“使命”?
对于每个“文件夹”(公司,约和任务),我必须呈现不同的视图.
谁知道我该怎么做?
谢谢!
解决方法
首先,设置您的视图:
Views\ Company\ Index.aspx About.aspx Mission.aspx AnotherAction.aspx
在您的GlobalAsax.RegisterRoutes(RouteCollection routes)方法中:
public static void RegisterRoutes(RouteCollection routes) { // this will match urls starting with company/about,and then will call the particular // action (if it exists) routes.MapRoute("mission","company/about/{action}",new { controller = "Company"}); // the default route goes at the end... routes.MapRoute( "Default",// Route name "{controller}/{action}/{id}",// URL with parameters new { controller = "Home",action = "Index",id = "" } // Parameter defaults ); }
在控制器中:
CompanyController { public ViewResult Index() { return View(); } public ViewResult About() { return View(); } public ViewResult Mission() { return View(); } public ViewResult AnotherAction() { return View(); } }