• MVC4做网站后台:栏目管理1、添加栏目


    把栏目添加删除跟前台混在一起结构清晰,现在有了后台管理的区域就把后台管理相关的代码分开。

    要实现功能:

    1、添加栏目

    2、删除栏目

    3、修改栏目信息

    ……

    一、开始

    1、添加 接口InterfaceCategory,命名空间:Ninesky.Areas.Admin.Repository

    using Ninesky.Models;
    
    namespace Ninesky.Areas.Admin.Repository
    {
        /// <summary>
        /// 栏目接口
        /// <remarks>
        /// 版本v1.0
        /// 创建2013.11.12
        /// </remarks>
        /// </summary>
        interface InterfaceCategory
        {}
    }

    2、添加实现类CategoryRepository,命名空间:Ninesky.Areas.Admin.Repository,继承自InterfaceCategory

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Ninesky.Models;
    
    namespace Ninesky.Areas.Admin.Repository
    {
        /// <summary>
        /// 栏目实现类
        /// <remarks>
        /// 版本v1
        /// 创建2013.11.13
        /// </remarks>
        /// </summary>
        public class CategoryRepository:InterfaceCategory
        {
        }
    }

    3、添加栏目控制器CategoryController,命名空间namespace Ninesky.Areas.Admin.Controllers,继承自Controllers

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace Ninesky.Areas.Admin.Controllers
    {
        /// <summary>
        /// 栏目控制器
        /// <remarks>
        /// 版本v1.0
        /// 创建2013.11.13
        /// </remarks>
        /// </summary>
    [AdminAuthorize]
        public class CategoryController : Controller
        {
    
            public ActionResult Index()
            {
                return View();
            }
    
        }
    }

     public ActionResult Index() 为 

    /// <summary>
            /// 菜单
            /// </summary>
            /// <returns>局部视图</returns>
            public PartialViewResult Menu()
            {
                return PartialView();
            }

    添加视图

    <div id="westmenu">
        <div title="栏目管理" class="leftsidebar">
            <ul>
                <li>@Html.ActionLink("添加栏目", "Add", "Category", null, new { @class = "westmenulink" })</li>
            </ul>
        </div>
    </div>
    <script type="text/javascript">
        westMenu();
    </script>

    打开global.js,在$(document).ready中添加代码

    $("#cagegory_cfg").click(function () {
            $("#west").load("Category/Menu", function () {
                $("#westmenu").accordion({
                    animate: false,
                    border: false
                });
            });
        });

    点下栏目管理看,左侧有添加栏目菜单了,下面开始添加栏目

    image

    一、添加栏目

    InterfaceCategory中添加代码

    /// <summary>
            /// 添加栏目
            /// </summary>
            /// <param name="category">栏目</param>
            /// <returns>布尔值。true表示添加成功,false表示失败。</returns>
            bool Add(Category category);

    CategoryRepository中添加代码

    public bool Add(Category category)
            {
                using (NineskyContext _nineskyContext = new NineskyContext())
                {
                    _nineskyContext.Categorys.Add(category);
                    return _nineskyContext.SaveChanges() > 0;
                }
            }

     

    =====

    未完待续。。

  • 相关阅读:
    falsk简单项目示例
    bootstrap基础
    flask models循环使用和migrate迁移脚本
    flask-script
    flask 钩子函数
    flask get和post请求使用
    flask SQLALchemy外键及约束
    flask SQLAlchemy
    关于虚拟机端口转发的一次理解和记录
    记录一次VMware与xshell远程链接的总结
  • 原文地址:https://www.cnblogs.com/mzwhj/p/3422339.html
Copyright © 2020-2023  润新知