首页 新闻 会员 周边

MVC3下的Area怎么用的,在Html.ActionLink中要怎么写?

0
悬赏园豆:10 [已解决问题] 解决于 2012-04-25 08:18

MVC3下的Area怎么用的,在Html.ActionLink中要怎么写,能否写个Demo?

tab_china的主页 tab_china | 初学一级 | 园豆:54
提问于:2012-04-24 10:59
< >
分享
最佳答案
-1

在项目上右键,添加Area(如Demo),VS会在项目下生成一个Areas文件夹,里面有个DemoAreaRegistration类,代码如下:

public class DemoAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Demo";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Demo_default",
            "Demo/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }
}

在项目的Global.asax.cs的Application_Start()方法里有这样一行代码(没有自己加):

AreaRegistration.RegisterAllAreas();

这个就是注册Area路径的。

Html.ActionLink中要这样写:

@Html.ActionLink("TestText", "Index", "Test", new { area = "Demo" }, null)

其中Index是Action,Test是Controller

收获园豆:10
artwl | 专家六级 |园豆:16736 | 2012-04-24 11:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册