如何在ASP.NET MVC中配置3个级别的URL?
发布时间:2021-01-24 09:04:03 所属栏目: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会话有IsNewSession == true,那我的意思是什
- asp.net – 脚本标签和链接标签进入asp:内容或外部
- LoginView中的ASP.NET LoginStatus不会触发LoggingOut事件
- 有没有办法将内部控件放在ASP.NET自定义控件中?
- asp.net核心 – 如何排除在ASP.NET Core中发布文件?
- asp.net-mvc – 当注入服务或控制器的依赖关系太多时,重构策
- asp.net-mvc – ASP.NET MVC中的WebApi [FromUri]是什么?
- asp.net-mvc – 有没有办法重命名RequestVerificationToken
- ASP.NET和System.Diagnostics跟踪 – 我错过了什么,或者这是
推荐文章
站长推荐
- asp.net-mvc – 在Controller操作方法中重用代码
- asp.net – 通过邮件发送wcf服务消费表单数据
- asp.net中XML如何做增删改查操作
- 我应该在ASP.NET MVC中构建我的下一个Web应用程序
- asp.net-mvc – 为什么在视图引擎中指定位置时,v
- asp.net-mvc – 在EditorFor for child对象中使用
- asp.net-mvc-3 – Telerik MVC网格,在运行时从集
- ASP.NET(C#)应用程序配置文件app.config/web.con
- asp.net-identity交易问题
- asp.net-core – ASP.Net 5类库中的EntityFramew
热点阅读
