如何在ASP.NET MVC中配置3个级别的URL?
发布时间:2021-01-24 08:12:00 所属栏目: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文件后缀名随心所欲
- asp.net-mvc-3 – 如何避免使用MVC3 FileContent
- 加快ASP.NET中的构建时间
- asp.net-mvc – 为什么在视图引擎中指定位置时,v
- asp.net-mvc – 使用AD的ASP.NET MVC表单Auth在本
- 从代码隐藏调用ASP.NET Web API
- asp.net-mvc – 允许一个人一次使用帐户的可重用
- asp.net-mvc – asp.net mvc如何正确测试控制器
- asp.net-mvc – ASP.NET MVC的Content / Themes
- asp.net – 在将MVC和路由添加到WebForms项目后,
热点阅读
