学用MVC4做网站六:后台管理


后台管理部分打算用一个单独的区域。主要进行网站的设置和管理,初步设想实现功能如下:

image

首先建立区域Admin。

在项目上点右键->添加->区域。输入名称“Admin”确定。

image

创建后新增的目录

image

从图中可以看到,区域有自己的模型。控制器、视图和路由,就像一个子项目。

双击打开ControlAreaRegistration.cs

更改代码如下:

using System.Web.Mvc;

namespace Ninesky.Areas.Admin
{
    public class ControlAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "Admin";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional } ,    
                new string[] { "Ninesky.Areas.Admin.Controllers" }
            );
        }
    }
}

同样,RouteConfig.cs文件的默认路由也要加上命名空间,改完后的样子

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}/{page}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, page = UrlParameter.Optional },
                namespaces: new string[] { "Ninesky.Controllers" }
                );

今天就写这儿。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM