如何在ASP.NET MVC中配置3个级别的URL?
发布时间:2021-01-24 07:03:28 所属栏目:asp.Net 来源:互联网
导读:使用ASP.NET MVC,我需要像这样配置我的URL: www.foo.com/company:渲染查看公司 www.foo.com/company/about:渲染查看公司 www.foo.com/company/about/mission:渲染查看任务 如果“公司”是我的控制者而“约”是我的行动,应该是什么“使命”? 对于每个“文
使用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(); } } (编辑:百色站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 当注入服务或控制器的依赖关系太多时,重构策
- asp.net-mvc – 在EditorFor for child对象中使用时,MVC无法
- 用户控件在asp.net和Performance中
- asp.net-mvc-3 – CopyAllFilesToSingleFolderForPackageDe
- ASP.NET MVC AJAX文档在哪里?
- asp.net-mvc – 如何设置AntiForgeryToken cookie路径
- asp.net-mvc – 使用Entity FrameWork保存更改/更新数据集中
- asp.net-mvc – 从MVC版本1迁移后,ASP.NET MVC 2 actionlin
- asp.net – 登录后对Membership.GetAllUsers()的例外情况:
- asp.net html控件的File控件实现多文件上传实例分享