如何在ASP.NET MVC中配置3个级别的URL?
发布时间:2021-01-24 07:06:20 所属栏目: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 – 如何从WCF客户端拦截raw soap request / respon
- 在使用ASP.NET会话时是否可以强制请求并发?
- asp.net – @ Url.Action在控制器中创建空值的参数之间添加
- asp.net-mvc – 如何在asp.net mvc中处理分页?
- ASP.NET中TextBox使用Ajax控件显示日期不全的问题解决方法
- asp.net-mvc – ASP.NET MVC会话超时,绝对还是滑动?
- asp.net 如何接收JSON作为MVC 5操作方法参数
- asp.net – 是否可以在源代码中使用iframe和localhost地址?
- asp.net-mvc – 为什么在我的ASP MVC4应用程序中重定向资源
- asp.net-mvc – mvc razor @helper可以返回非编码标签吗?