如何在ASP.NET MVC中配置3个级别的URL?
发布时间:2021-01-24 00:53:23 所属栏目: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 – IIS Express(WebMatrix)打开外部连接
- kendo-ui – 剑道网格刷新(数据绑定两次)
- asp.net-mvc – Razor并在ActionLinks上指定css类名
- asp.net – 在Web.config帮助中定义tagPrefixes
- asp.net – UpdatePanel中的动态创建控件?
- asp.net – 根据参数应用不同的XSLT模板
- asp.net-mvc-3 – 是否可能获得一个ASP.NET MVC 3项目工作在
- ASP.NET MVC是否使Web表单成为旧版平台?
- 如何从经典ASP输出Excel * .xls文件
- 使用SharpZipLib压缩打包多个内存中的文件
推荐文章
站长推荐
- asp.net – 在MVC3或IIS 7.5中禁用x-frame-optio
- .net – asp:GridView文本框始终返回空值
- asp.net-mvc – ASP.NET MVC模型/ ViewModel验证
- asp.net-mvc-3 – ASP.net MVC – 模型绑定不包括
- asp.net – .NET Web API 2 OWIN承载令牌认证
- asp.net-mvc – Azure git部署 – 第二个程序集中
- SqlServer如何给表添加新的字段以及字段注释
- asp.net – 如何扩展aspnet成员身份验证表?
- asp.net – 无法加载文件或程序集System.Web.Htt
- asp.net-mvc – Visual Studio 2010 Full和ASP.N
热点阅读