如何在ASP.NET MVC中配置3个级别的URL?
发布时间:2021-01-24 06:20:41 所属栏目: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中使用querystring的最佳做法?
- asp.net core webapi 服务端配置跨域的实例
- 实体框架 – WebApi OData:$filter’any’或’all’查询不
- asp.net – VB.NET – 如何使用Active Directory将SID转换为
- WCF服务与ASP.NET Web Api
- 在mvc4 asp.net中的Razor View中的模型声明
- asp.net-mvc-4 – ASP.NET MVC 4通过ActionLink传递对象变量
- ASP.NET MVC4 Razor模板简易分页效果
- asp.net-web-api – 首先使用ASP.NET Web API的EF5代码:更
- 如何在asp.net会员中手动更改密码?
推荐文章
站长推荐
热点阅读
