zoukankan      html  css  js  c++  java
  • 学用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" }
                    );

    今天就写这儿。

  • 相关阅读:
    python列表作为默认参数的问题
    python 强制停止线程
    cProfile 分析python运行时间
    python global全局变量 模块通信问题
    ajax请求数据get、post
    vue中加载three.js全景图
    vue中加载three.js的gltf模型
    vue-cli2.x与vue-cli3.x的搭建
    cesium加载gltf模型
    vue/cli3引入cesium
  • 原文地址:https://www.cnblogs.com/mzwhj/p/3114527.html
Copyright © 2011-2022 走看看