如何配置ASP.NET MVC3地区 [英] How to Configure Areas in ASP.NET MVC3
问题描述
有没有人知道如何在ASP.NET MVC3配置领域。
我这里了解动物园在的文章。
但是,这篇文章不是基于MVC3。
在MVC3没有在 RouteCollection路线
命名的无功能 MapRootArea
这是在Global.asax中找到
Is anyone knows how to Configure Areas in ASP.NET MVC3.
I read an article about Areas in here.
But that article is not based on MVC3.
In MVC3 there is no function named MapRootArea
in RouteCollection routes
which is found in Global.asax
routes.MapRootArea("{controller}/{action}/{id}",
"AreasDemo",
new { controller = "Home", action = "Index", id = "" });
当我创建一个使用MVC3一个新领域,我有一类从 AreaRegistration
继承了面积,看起来就像如下:(这里博客是区域名称)
When i create a New Area using MVC3, i got a class of that area which inherited from AreaRegistration
and look like following: (here Blogs is the area name)
public class BlogsAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Blogs";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Blogs_default",
"Blogs/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
会有人请帮助我如何在MVC3配置区域。任何一种联系将是有帮助的。
Would anyone please help me how do i configure area in MVC3. Any kind of link would be helpful also.
推荐答案
右键单击Web项目,然后选择添加 - >区域......然后键入区域的名称和Visual Studio将是剩下的工作以产生所需的所有类。例如,域名注册可能是这样的:
Right click on your web project and select Add -> Area... Then type the name of the area and Visual Studio will take care of the rest which is to generate all the necessary classes. For example the area registration might look like this:
public class AreasDemoAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "AreasDemo";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"AreasDemo_default",
"AreasDemo/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
和的Application_Start
你的的Global.asax
所有你需要的是:
AreaRegistration.RegisterAllAreas();
这篇关于如何配置ASP.NET MVC3地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!