ASP.NET.4.5.1+MVC5.0设置系统角色与权限(二)

系统角色篇

数据结构

用户管理

Controller代码

代码如下:

public class SystemUserController : Controller
    {
        //public void Log()
        //{
        //    string meg = "";
        //    int user = int.Parse(CookieHelper.GetValue("SysUserID"));
        //    string ip = IPHelper.GetUserIp;
        //    foreach (var item in RouteData.Values)
        //    {
        //        meg += item.Key.ToUpper() + ":" + item.Value + "|";
        //    }
        //    AuditLogConfig.InsertAuditLog(meg, user, ip);
        //}
        SystemUserRepository sysuserrepository = new SystemUserRepository();
        RoleRepository roleryrepository = new RoleRepository();
        DepartmentRepository departmentryrepository = new DepartmentRepository();
        JobRepository jobryrepository = new JobRepository();
        #region 列表页
        /// <summary>
        /// 列表页
        /// </summary>
        /// <param name="page">当前页</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Index(int? page)
        {
            ViewBag.ControllerName=RouteData.Values["controller"].ToString().ToLower();
            CookieHelper.Del("LogName");
            var source = sysuserrepository.GetPageModelList(10, page ?? 1, -1);
            return View(source);
        }
        #endregion
        #region 添加管理员
        /// <summary>
        /// 添加页
        /// </summary>
        /// <param name="model">管理员实体类</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Add(SystemUser model)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var rolelist = roleryrepository.GetModelListByState(1);
            ViewBag.RoleID = SelectListExtension.ToSelectList(rolelist, d => d.RoleName, d => d.RoleID.ToString());
            var departmentlist = departmentryrepository.GetModelListByState(1);
            ViewBag.DepartmentID = SelectListExtension.ToSelectList(departmentlist, d => d.DepartmentName, d => d.DepartmentID.ToString());
            var joblist = jobryrepository.GetModelListByState(1);
            ViewBag.JobID = SelectListExtension.ToSelectList(joblist, d => d.JobName, d => d.JobID.ToString());
            // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0);
            return View();
        }
        /// <summary>
        /// 添加事件
        /// </summary>
        /// <param name="model">实体类</param>
        /// <param name="fc"></param>
        /// <returns></returns>
        [Authorize, HttpPost, ValidateInput(false)]
        public ActionResult Add(SystemUser model, FormCollection fc)
        {
            model.State = 1;
            model.CreateTime = DateTime.Now;
            sysuserrepository.SaveOrEditModel(model);
            return RedirectToAction("Index");
        }
        #endregion
        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">删除编号</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Delete(int id)
        {
            try
            {
                var model = sysuserrepository.GetModel(id);
                if (model != null)
                {
                    sysuserrepository.DeleteModel(id);
                    return RedirectToAction("Index");
                }
                else
                    return View("404");
                //throw new Exception("方法出错!");
            }
            catch (Exception ex)
            {
                Log4netHelper.InvokeErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "删除方法出错-Author:ryanding IP地址[" + IPHelper.GetUserIp + "]" + "操作人ID:" + CookieHelper.GetValue("SystemUserID"), ex);
                return View("404");
            }
        }
        #endregion
        #region 查询
        [Authorize]
        public ActionResult Search(int? page)
        {
            string logname = "";
            if (page == null)
            {
                logname = Request.Form["KeyWord"];
                CookieHelper.SetObj("KeyWord", 0, logname);
            }
            else
                logname = CookieHelper.GetValue("KeyWord");
            var query = QueryBuilder.Create<SystemUser>().Like(d => d.LogName, logname);
            var source = sysuserrepository.GetModelList().Where(query.Expression);
            return View(new Pager<SystemUser>(source, page ?? 1));
        }
        #endregion
        #region 编辑
        [Authorize]
        public ActionResult Edit(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = sysuserrepository.GetModel(id);
            if (model != null)
            {
                var rolelist = roleryrepository.GetModelListByState(1);
                ViewBag.RoleID = SelectListExtension.ToSelectList(rolelist, d => d.RoleName, d => d.RoleID.ToString(),model.RoleID);
                var departmentlist = departmentryrepository.GetModelListByState(1);
                ViewBag.DepartmentID = SelectListExtension.ToSelectList(departmentlist, d => d.DepartmentName, d => d.DepartmentID.ToString(), model.DepartmentID);
                var joblist = jobryrepository.GetModelListByState(1);
                ViewBag.JobID = SelectListExtension.ToSelectList(joblist, d => d.JobName, d => d.JobID.ToString(), model.JobID);
                ViewData["State"] = SelectListHelper.GetStateSelectList(model.State);
                return View(model);
            }
            else
                return View("404");
        }
        [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]
        public ActionResult Edit(int id, FormCollection fc)
        {
            var model = sysuserrepository.GetModel(id);
            if (model != null)
            {
                string password = model.Password;
                if (Request.Form["PassWord"] != "")
                {
                    UpdateModel(model);
                    sysuserrepository.SaveOrEditModel(model);
                }
                else
                {
                    UpdateModel(model);
                    model.Password = password;
                    sysuserrepository.SaveOrEditModel(model);
                }
                return RedirectToAction("index");
            }
            else
                return View("404");
        }
        #endregion
        #region 用户名是否可用
        //检测用户名是否可用
        [HttpPost]
        public ActionResult GetUsers(string param, string name)
        {
            if (sysuserrepository.IsExist(param))
                return Content("y");
            else
                return Content("用户名已存在");
        }
        #endregion
        public bool Login()
        {
            try
            {
                //TODO:
                throw new Exception("方法出错!");
            }
            catch (Exception ex)
            {
                Log4netHelper.InvokeErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "登录方法Login出错-Author:ryanding IP地址[" + IPHelper.GetUserIp + "]" + "操作人ID:" + CookieHelper.GetValue("SystemUserID"), ex);
                return false;
            }
            return true;
        }
    }

View代码

Index.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.SystemUser>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
            <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                    <span class="sple"><a href="/systemuser/add">添加用户</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">用户编号</td>
                        <td class="rgtd3">登录名</td>
                        <td class="rgtd3">手机</td>
                        <td class="rgtd3">Email</td>
                        <td class="rgtd3">昵称</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.SystemUserID</td>
                            <td class="rgtd3">@(item.LogName)</td>
                            <td class="rgtd3">@item.Mobile</td>
                            <td class="rgtd3">@item.Email</td>
                            <td class="rgtd3">@item.TrueName</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/systemuser/delete/@item.SystemUserID">删除</a> | <a href="/systemuser/edit/@item.SystemUserID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
        <div class="rg5">
            @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList)
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#@(ViewBag.ControllerName)sys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".@(ViewBag.ControllerName)sys").each(function (index, item) {
        $(this).show();
    });
</script>

Add.cshtml

代码如下:

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="contrgcon">
    <div class="rgtit3">
        <div class="tit1">
            <h3>添加用户</h3>
        </div>
        <div class="rgtit3con">
            @using (Html.BeginForm())
            {
                <dl>
                    <dd class="dc1">用户名:</dd>
                    <dd>
                        <input name="LogName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">昵称:</dd>
                    <dd>
                        <input name="TrueName" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">Email:</dd>
                    <dd>
                        <input type="text" name="Email" id="Email" class="rgtxt2" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">手机号:</dd>
                    <dd>
                        <input type="text" name="Mobile" id="Mobile" class="rgtxt2" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">密码:</dd>
                    <dd>
                        <input type="text" name="Password" id="Password" class="rgtxt2" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">确认密码:</dd>
                    <dd>
                        <input type="text" name="PassWordto" id="PassWordto" class="rgtxt2" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">岗位:</dd>
                    <dd>
                        @Html.DropDownList("JobID", ViewBag.JobID as SelectList)
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">部门:</dd>
                    <dd>
                         @Html.DropDownList("DepartmentID", ViewBag.DepartmentID as SelectList)
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">角色:</dd>
                    <dd>
                         @Html.DropDownList("RoleID", ViewBag.RoleID as SelectList)
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <input type="submit" value="提 交" class="rgbut4" />
                    </dd>
                </dl>
            }
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#@(ViewBag.ControllerName)sys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".@(ViewBag.ControllerName)sys").each(function (index, item) {
        $(this).show();
    });
</script>

Edit.cshtml

代码如下:

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Models.SystemUser
<div class="contrgcon">
    <div class="rgtit3">
        <div class="tit1">
            <h3>编辑用户</h3>
        </div>
        <div class="rgtit3con">
            @using (Html.BeginForm())
            {
                <dl>
                    <dd class="dc1">用户名:</dd>
                    <dd>
                        <input name="LogName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@Model.LogName"/>
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">昵称:</dd>
                    <dd>
                        <input name="TrueName" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@Model.TrueName" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">Email:</dd>
                    <dd>
                        <input type="text" name="Email" id="Email" class="rgtxt2" value="@Model.Email" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">手机号:</dd>
                    <dd>
                        <input type="text" name="Mobile" id="Mobile" class="rgtxt2" value="@Model.Mobile" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">修改密码:</dd>
                    <dd>
                        <input type="text" name="Password" id="Password" class="rgtxt2" value="@Model.Password" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">岗位:</dd>
                    <dd>
                        @Html.DropDownList("JobID", ViewBag.JobID as SelectList)
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">部门:</dd>
                    <dd>
                         @Html.DropDownList("DepartmentID", ViewBag.DepartmentID as SelectList)
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">角色:</dd>
                    <dd>
                         @Html.DropDownList("RoleID", ViewBag.RoleID as SelectList)
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <input type="submit" value="提 交" class="rgbut4" />
                    </dd>
                </dl>
            }
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#@(ViewBag.ControllerName)sys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".@(ViewBag.ControllerName)sys").each(function (index, item) {
        $(this).show();
    });
</script>

Search.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.SystemUser>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
            <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                    <span class="sple"><a href="/systemuser/add">添加用户</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">用户编号</td>
                        <td class="rgtd3">登录名</td>
                        <td class="rgtd3">手机</td>
                        <td class="rgtd3">Email</td>
                        <td class="rgtd3">昵称</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.SystemUserID</td>
                            <td class="rgtd3">@(item.LogName)</td>
                            <td class="rgtd3">@item.Mobile</td>
                            <td class="rgtd3">@item.Email</td>
                            <td class="rgtd3">@item.TrueName</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/systemuser/delete/@item.SystemUserID">删除</a> | <a href="/systemuser/edit/@item.SystemUserID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#@(ViewBag.ControllerName)sys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".@(ViewBag.ControllerName)sys").each(function (index, item) {
        $(this).show();
    });
</script>

角色管理

Controller代码

代码如下:

public class RoleController : Controller
   {
       RoleRepository roleryrepository = new RoleRepository();
       MenuRepository menurepository = new MenuRepository();
       RoleMenuMappingRepository rmmrepositoy = new RoleMenuMappingRepository();
       #region 列表
       /// <summary>
       /// 默认页面
       /// </summary>
       /// <returns></returns>
       ///
       [Authorize]
       public ActionResult Index(int? page)
       {
           ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
           var source = roleryrepository.GetModelList();
           return View(roleryrepository.GetPageModelList(source, 10, page ?? 1));
       }
       #endregion
       #region 添加
       /// <summary>
       /// 添加页
       /// </summary>
       /// <param name="model">实体类</param>
       /// <returns></returns>
       [Authorize]
       public ActionResult Add(Role model)
       {
           ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
           var menu = menurepository.GetModelListByState(1);
           ViewBag.Menu = new SelectList(menu, "MenuID", "MenuName");
           // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0);
           return View();
       }
       public string Log()
       {
           string meg = "";
           //int user = int.Parse(CookieHelper.GetValue("SysUserID"));
           //string ip = IPHelper.GetUserIp;
           foreach (var item in RouteData.Values)
           {
               meg += item.Key.ToUpper() + ":" + item.Value + "|";
           }
           return meg;
       }
       /// <summary>
       /// 添加事件
       /// </summary>
       /// <param name="model">实体类</param>
       /// <param name="fc"></param>
       /// <returns></returns>
       [Authorize, HttpPost, ValidateInput(false)]
       public ActionResult Add(Role model, FormCollection fc, int[] Menu)
       {
           try
           {
               ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
               model.State = 1;
               model.CreateTime = DateTime.Now;
               roleryrepository.SaveOrEditModel(model);
               if (Menu.Length > 0)
               {
                   foreach (int gsi in Menu)
                   {
                       RoleMenuMapping rmm = new RoleMenuMapping();
                       rmm.MenuID = gsi;
                       rmm.RoleID = model.RoleID;
                       rmmrepositoy.SaveOrEditModel(rmm);
                   }
               }
               else
               {
                   return RedirectToAction("Index");
               }
           }
           catch (Exception ex)
           {
               Log4netHelper.InvokeErrorLog(MethodBase.GetCurrentMethod().DeclaringType, ViewBag.ControllerName + "添加方法出错-Author:ryanding IP地址[" + IPHelper.GetUserIp + "]" + "操作人ID:" + CookieHelper.GetValue("SystemUserID") + "当前来源信息:" + Log(), ex);
           }
           return View("404");
       }
       #endregion
       #region 删除
       /// <summary>
       /// 删除
       /// </summary>
       /// <param name="id">删除编号</param>
       /// <returns></returns>
       [Authorize]
       public ActionResult Delete(int id)
       {
           ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
           var model = roleryrepository.GetModel(id);
           model.State = 0;
           if (model != null)
           {
               roleryrepository.SaveOrEditModel(model);
               return RedirectToAction("index");
           }
           else
               return View("404");
       }
       #endregion
       #region 查询
       [Authorize]
       public ActionResult Search(int? page)
       {
           ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
           string name = "";
           if (page == null)
           {
               name = Request.Form["KeyWord"];
               CookieHelper.SetObj("KeyWord", 0, name);
           }
           else
               name = CookieHelper.GetValue("KeyWord");
           var query = QueryBuilder.Create<Role>().Like(d => d.RoleName, name);
           var source = roleryrepository.GetModelList().Where(query.Expression);
           return View(new Pager<Role>(source, page ?? 1, 10));
       }
       #endregion
       #region 编辑
       [Authorize]
       public ActionResult Edit(int id)
       {
           ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
           var rmmList = rmmrepositoy.GetModelList().Where(d => d.RoleID == id);
           var menu = menurepository.GetModelListByState(1);
           ViewBag.Menu = new SelectList(menu, "MenuID", "MenuName", string.Join(",", rmmList.Select(p => p.MenuID)));
           var model = roleryrepository.GetModel(id);
           if (model != null)
           {
               ViewData["State"] = SelectListHelper.GetStateSelectList(model.State);
               return View(model);
           }
           else
               return View("404");
       }
       [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]
       public ActionResult Edit(int id, FormCollection fc, int[] Menu)
       {
           ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
           var model = roleryrepository.GetModel(id);
           if (model != null)
           {
               if (Menu.Length > 0)
               {
                   rmmrepositoy.DeleteModel(rmmrepositoy.GetModelList().Where(d => d.RoleID == model.RoleID));
                   foreach (int gsi in Menu)
                   {
                       RoleMenuMapping rmm = new RoleMenuMapping();
                       rmm.MenuID = gsi;
                       rmm.RoleID = model.RoleID;
                       rmmrepositoy.SaveOrEditModel(rmm);
                   }
               }
               UpdateModel(model);
               roleryrepository.SaveOrEditModel(model);
               return RedirectToAction("index");
           }
           else
               return View("404");
       }
       #endregion
   }

View代码

Index.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.Role>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
            <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                   <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">编号</td>
                        <td class="rgtd2">角色名称</td>
                        <td class="rgtd3">角色内容</td>
                        <td class="rgtd3">创建时间</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.RoleID</td>
                            <td class="rgtd2">@item.RoleName</td>
                            <td class="rgtd3">@item.RoleContent</td>
                            <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.RoleID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.RoleID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
        <div class="rg5">
           @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList);
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Add.cshtml

代码如下:

@using SJCRM.Helpers
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="contrgcon">
    <div class="rgtit3">
        <div class="tit1">
            <h3>添加</h3>
        </div>
        <div class="rgtit3con">
            @using (Html.BeginForm())
            {
                <dl>
                    <dd class="dc1">角色名称:</dd>
                    <dd>
                        <input name="RoleName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入名称" />
                    </dd>
                </dl>
      <dl>
                    <dd class="dc1">角色权限:</dd>
                    <dd>
                        @Html.CheckBoxList("Menu")
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">角色内容:</dd>
                    <dd>
                         <textarea rows="10" cols="82" name="RoleContent" id="RoleContent"></textarea>
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <input type="submit" value="提 交" class="rgbut4" />
                    </dd>
                </dl>
            }
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Edit.cshtml

代码如下:

@using SJCRM.Helpers
 @{
     ViewBag.Title = "Add";
     Layout = "~/Views/Shared/_Layout.cshtml";
 }
 @model SJCRM.Models.Role
 <div class="contrgcon">
     <div class="rgtit3">
         <div class="tit1">
             <h3>编辑</h3>
         </div>
         <div class="rgtit3con">
             @using (Html.BeginForm())
             {
                 <dl>
                     <dd class="dc1">角色名称:</dd>
                     <dd>
                         <input name="RoleName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入名称" value="@Model.RoleName"/>
                     </dd>
                 </dl>
       <dl>
                     <dd class="dc1">角色权限:</dd>
                     <dd>
                         @Html.CheckBoxList("Menu")
                     </dd>
                 </dl>
                 <dl>
                     <dd class="dc1">角色内容:</dd>
                     <dd>
                          <textarea rows="10" cols="82" name="RoleContent" id="RoleContent">@Model.RoleName</textarea>
                     </dd>
                 </dl>
                 <dl>
                     <dd>
                         <input type="submit" value="提 交" class="rgbut4" />
                     </dd>
                 </dl>
             }
         </div>
     </div>
 </div>
 <script>
     //菜单显示
     $("#systemusersys").addClass("hbg");
     $("#@(ViewBag.ControllerName)").removeClass("navli");
     $("#@(ViewBag.ControllerName)").addClass("navlihg");
     $(".systemusersys").each(function (index, item) {
         $(this).show();
     });
 </script>

Search.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.Role>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
            <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                   <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">编号</td>
                        <td class="rgtd2">角色名称</td>
                        <td class="rgtd3">角色内容</td>
                        <td class="rgtd3">创建时间</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.RoleID</td>
                            <td class="rgtd2">@item.RoleName</td>
                            <td class="rgtd3">@item.RoleContent</td>
                            <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.RoleID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.RoleID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

菜单管理

Controller代码

代码如下:

public class MenuController : Controller
    {
        MenuRepository repository = new MenuRepository();
        #region 列表
        /// <summary>
        /// 默认页面
        /// </summary>
        /// <returns></returns>
        ///
        [Authorize]
        public ActionResult Index(int? page)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var source = repository.GetModelListByState(1);
            return View(repository.GetPageModelList(source, 10, page ?? 1));
        }
        #endregion
        #region 添加
        /// <summary>
        /// 添加页
        /// </summary>
        /// <param name="model">实体类</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Add(Menu model)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0);
            return View();
        }
        /// <summary>
        /// 添加事件
        /// </summary>
        /// <param name="model">实体类</param>
        /// <param name="fc"></param>
        /// <returns></returns>
        [Authorize, HttpPost, ValidateInput(false)]
        public ActionResult Add(Menu model, FormCollection fc)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            model.State = 1;
            model.CreateTime = DateTime.Now;
            repository.SaveOrEditModel(model);
            return RedirectToAction("Index");
        }
        #endregion
        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">删除编号</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Delete(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = repository.GetModel(id);
            model.State = 0;
            if (model != null)
            {
                repository.SaveOrEditModel(model);
                return RedirectToAction("index");
            }
            else
                return View("404");
            //var model = categoryrepository.GetModel(id);
            //if (model != null)
            //{
            //    categoryrepository.DeleteModel(id);
            //    return RedirectToAction("Index");
            //}
            //else
            //    return View("404");
        }
        #endregion
        #region 查询
        [Authorize]
        public ActionResult Search(int? page)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            string name = "";
            if (page == null)
            {
                name = Request.Form["KeyWord"];
                CookieHelper.SetObj("KeyWord", 0, name);
            }
            else
                name = CookieHelper.GetValue("KeyWord");
            var query = QueryBuilder.Create<Menu>().Like(d => d.MenuName, name);
            var source = repository.GetModelList().Where(query.Expression);
            return View(new Pager<Menu>(source, page ?? 1, 10));
        }
        #endregion
        #region 编辑
        [Authorize]
        public ActionResult Edit(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = repository.GetModel(id);
            if (model != null)
            {
                ViewData["State"] = SelectListHelper.GetStateSelectList(model.State);
                return View(model);
            }
            else
                return View("404");
        }
        [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]
        public ActionResult Edit(int id, FormCollection fc)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = repository.GetModel(id);
            if (model != null)
            {
                UpdateModel(model);
                repository.SaveOrEditModel(model);
                return RedirectToAction("index");
            }
            else
                return View("404");
        }
        #endregion
     }

View代码

Index.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.Menu>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
            <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                   <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">编号</td>
                        <td class="rgtd3">菜单名称</td>
                        <td class="rgtd3">别名样式</td>
                        <td class="rgtd3">连接地址</td>
                        <td class="rgtd3">创建时间</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.MenuID</td>
                            <td class="rgtd3">@item.MenuName</td>
                            <td class="rgtd3">@item.Alias</td>
                            <td class="rgtd3">@item.Url</td>
                            <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.MenuID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.MenuID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
        <div class="rg5">
           @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList);
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Add.cshtml

代码如下:

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="contrgcon">
    <div class="rgtit3">
        <div class="tit1">
            <h3>添加菜单</h3>
        </div>
        <div class="rgtit3con">
            @using (Html.BeginForm())
            {
                <dl>
                    <dd class="dc1">菜单名称:</dd>
                    <dd>
                        <input name="MenuName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">连接地址:</dd>
                    <dd>
                        <input name="Url" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">别名样式:</dd>
                    <dd>
                        <input name="Alias" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" />
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <input type="submit" value="提 交" class="rgbut4" />
                    </dd>
                </dl>
            }
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Edit.cshtml

代码如下:

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Models.Menu
<div class="contrgcon">
    <div class="rgtit3">
        <div class="tit1">
            <h3>编辑</h3>
        </div>
        <div class="rgtit3con">
            @using (Html.BeginForm())
            {
                <dl>
                    <dd class="dc1">菜单名称:</dd>
                    <dd>
                        <input name="MenuName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@Model.MenuName" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">连接地址:</dd>
                    <dd>
                        <input name="Url" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@Model.Url" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">别名样式:</dd>
                    <dd>
                        <input name="Alias" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@Model.Alias" />
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <input type="submit" value="提 交" class="rgbut4" />
                    </dd>
                </dl>
            }
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Search.cshtml

代码如下:

@{
     ViewBag.Title = "Index";
     Layout = "~/Views/Shared/_Layout.cshtml";
 }
 @model SJCRM.Helpers.Pager<SJCRM.Models.Menu>
 <div class="contrgcon">
     <div class="contrg_list">
         <div class="rgtit">
             <form method="post" action="/@ViewBag.ControllerName/search">
                 <dl>
                     <dd>关键词:</dd>
                     <dd>
                         <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                     <dd>
                         <input type="submit" value="查 询" class="rgbut1" /></dd>
                 </dl>
             </form>
         </div>
         <div class="rgc">
             <dl class="rgt11">
                 <dt>
                    <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span>
                 </dt>
             </dl>
             <div class="rg3">
                 <table width="100%" border="0" cellspacing="0" cellpadding="0">
                     <tr>
                         <td class="rgtd2">编号</td>
                         <td class="rgtd3">菜单名称</td>
                         <td class="rgtd3">别名样式</td>
                         <td class="rgtd3">连接地址</td>
                         <td class="rgtd3">创建时间</td>
                         <td class="rgtd3">状态</td>
                         <td class="rgtd4">操作</td>
                     </tr>
                 </table>
             </div>
             <div class="rg4">
                 @{int classnum = 1;}
                 @foreach (var item in Model)
                 {
                     <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                    {<text>class="rgbg2"</text>}>
                         <tr>
                             <td class="rgtd2">@item.MenuID</td>
                             <td class="rgtd3">@item.MenuName</td>
                             <td class="rgtd3">@item.Alias</td>
                             <td class="rgtd3">@item.Url</td>
                             <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td>
                             <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                             <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.MenuID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.MenuID">编辑</a>  </td>
                         </tr>
                     </table>
                                                                                    classnum = classnum + 1;
                 }
             </div>
         </div>
     </div>
 </div>
 <script>
     //菜单显示
     $("#systemusersys").addClass("hbg");
     $("#@(ViewBag.ControllerName)").removeClass("navli");
     $("#@(ViewBag.ControllerName)").addClass("navlihg");
     $(".systemusersys").each(function (index, item) {
         $(this).show();
     });
 </script>

部门管理

Controller代码

代码如下:

public class DepartmentController : Controller
    {
        DepartmentRepository departmentryrepository = new DepartmentRepository();
        #region 列表
        /// <summary>
        /// 默认页面
        /// </summary>
        /// <returns></returns>
        ///
        [Authorize]
        public ActionResult Index(int? page)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var source = departmentryrepository.GetModelList();
            return View(departmentryrepository.GetPageModelList(source, 10, page ?? 1));
        }
        #endregion
        #region 添加
        /// <summary>
        /// 添加页
        /// </summary>
        /// <param name="model">实体类</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Add(Department model)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0);
            return View();
        }
        /// <summary>
        /// 添加事件
        /// </summary>
        /// <param name="model">实体类</param>
        /// <param name="fc"></param>
        /// <returns></returns>
        [Authorize, HttpPost, ValidateInput(false)]
        public ActionResult Add(Department model, FormCollection fc)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            model.State = 1;
            model.CreateTime = DateTime.Now;
            departmentryrepository.SaveOrEditModel(model);
            return RedirectToAction("Index");
        }
        #endregion
        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">删除编号</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Delete(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = departmentryrepository.GetModel(id);
            model.State = 0;
            if (model != null)
            {
                departmentryrepository.SaveOrEditModel(model);
                return RedirectToAction("index");
            }
            else
                return View("404");
            //var model = categoryrepository.GetModel(id);
            //if (model != null)
            //{
            //    categoryrepository.DeleteModel(id);
            //    return RedirectToAction("Index");
            //}
            //else
            //    return View("404");
        }
        #endregion
        #region 查询
        [Authorize]
        public ActionResult Search(int? page)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            string jobname = "";
            if (page == null)
            {
                jobname = Request.Form["KeyWord"];
                CookieHelper.SetObj("KeyWord", 0, jobname);
            }
            else
                jobname = CookieHelper.GetValue("KeyWord");
            var query = QueryBuilder.Create<Department>().Like(d => d.DepartmentName, jobname);
            var source = departmentryrepository.GetModelList().Where(query.Expression);
            return View(new Pager<Department>(source, page ?? 1, 10));
        }
        #endregion
        #region 编辑
        [Authorize]
        public ActionResult Edit(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = departmentryrepository.GetModel(id);
            if (model != null)
            {
                ViewData["State"] = SelectListHelper.GetStateSelectList(model.State);
                return View(model);
            }
            else
                return View("404");
        }
        [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]
        public ActionResult Edit(int id, FormCollection fc)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = departmentryrepository.GetModel(id);
            if (model != null)
            {
                UpdateModel(model);
                departmentryrepository.SaveOrEditModel(model);
                return RedirectToAction("index");
            }
            else
                return View("404");
        }
        #endregion
      }

View代码

Index.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.Department>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
             <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                   <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">编号</td>
                        <td class="rgtd2">部门名称</td>
                        <td class="rgtd3">是否销售</td>
                        <td class="rgtd3">创建时间</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.DepartmentID</td>
                            <td class="rgtd2">@item.DepartmentName</td>
                            <td class="rgtd3">@(item.IsSale == 1 ? "是" : "否")</td>
                            <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.DepartmentID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.DepartmentID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
        <div class="rg5">
           @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList);
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Add.cshtml

代码如下:

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="contrgcon">
    <div class="rgtit3">
        <div class="tit1">
            <h3>添加</h3>
        </div>
        <div class="rgtit3con">
            @using (Html.BeginForm())
            {
                <dl>
                    <dd class="dc1">部门名称:</dd>
                    <dd>
                        <input name="DepartmentName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">是否销售:</dd>
                    <dd>
                        <select name="IsSale">
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <input type="submit" value="提 交" class="rgbut4" />
                    </dd>
                </dl>
            }
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Edit.cshtml

代码如下:

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Models.Department
<div class="contrgcon">
    <div class="rgtit3">
        <div class="tit1">
            <h3>编辑</h3>
        </div>
        <div class="rgtit3con">
            @using (Html.BeginForm())
            {
                <dl>
                    <dd class="dc1">部门名称:</dd>
                    <dd>
                        <input name="DepartmentName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@Model.DepartmentName" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">是否销售:</dd>
                    <dd>
                        @UIHelper.IsSelect("IsSale", @Model.IsSale.ToString());
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <input type="submit" value="提 交" class="rgbut4" />
                    </dd>
                </dl>
            }
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Search.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.Department>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
             <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                   <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">编号</td>
                        <td class="rgtd2">部门名称</td>
                        <td class="rgtd3">是否销售</td>
                        <td class="rgtd3">创建时间</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.DepartmentID</td>
                            <td class="rgtd2">@item.DepartmentName</td>
                            <td class="rgtd3">@(item.IsSale == 1 ? "是" : "否")</td>
                            <td class="rgtd3">@String.Format("{0:yyyy-MM-dd}", item.CreateTime)</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/@ViewBag.ControllerName/delete/@item.DepartmentID">删除</a> | <a href="/@ViewBag.ControllerName/edit/@item.DepartmentID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

岗位管理

Controller代码

代码如下:

public class JobController : Controller
    {
        JobRepository jobryrepository = new JobRepository();
        #region 岗位列表
        /// <summary>
        /// 默认页面
        /// </summary>
        /// <returns></returns>
        ///
        [Authorize]
        public ActionResult Index(int? page)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var source = jobryrepository.GetModelListByState(1);
            return View(jobryrepository.GetPageModelList(source, 10, page ?? 1));
        }
        #endregion
        #region 添加
        /// <summary>
        /// 添加页
        /// </summary>
        /// <param name="model">实体类</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Add(Job model)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            // ViewData["State"] = SelectListHelper.GetIsOrNoSelectList(0);
            return View();
        }
        /// <summary>
        /// 添加事件
        /// </summary>
        /// <param name="model">实体类</param>
        /// <param name="fc"></param>
        /// <returns></returns>
        [Authorize, HttpPost, ValidateInput(false)]
        public ActionResult Add(Job model, FormCollection fc)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            model.State = 1;
            model.CreateTime = DateTime.Now;
            jobryrepository.SaveOrEditModel(model);
            return RedirectToAction("Index");
        }
        #endregion
        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">删除编号</param>
        /// <returns></returns>
        [Authorize]
        public ActionResult Delete(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = jobryrepository.GetModel(id);
            model.State = 0;
            if (model != null)
            {
                jobryrepository.SaveOrEditModel(model);
                return RedirectToAction("index");
            }
            else
                return View("404");
            //var model = categoryrepository.GetModel(id);
            //if (model != null)
            //{
            //    categoryrepository.DeleteModel(id);
            //    return RedirectToAction("Index");
            //}
            //else
            //    return View("404");
        }
        #endregion
        #region 查询
        [Authorize]
        public ActionResult Search(int? page)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            string jobname = "";
            if (page == null)
            {
                jobname = Request.Form["KeyWord"];
                CookieHelper.SetObj("KeyWord", 0, jobname);
            }
            else
                jobname = CookieHelper.GetValue("KeyWord");
            var query = QueryBuilder.Create<Job>().Like(d => d.JobName, jobname);
            var source = jobryrepository.GetModelList().Where(query.Expression);
            return View(new Pager<Job>(source, page ?? 1, 10));
        }
        #endregion
        #region 编辑
        [Authorize]
        public ActionResult Edit(int id)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = jobryrepository.GetModel(id);
            if (model != null)
            {
                ViewData["State"] = SelectListHelper.GetStateSelectList(model.State);
                return View(model);
            }
            else
                return View("404");
        }
        [Authorize, AcceptVerbs(HttpVerbs.Post), ValidateInput(false)]
        public ActionResult Edit(int id, FormCollection fc)
        {
            ViewBag.ControllerName = RouteData.Values["controller"].ToString().ToLower();
            var model = jobryrepository.GetModel(id);
            if (model != null)
            {
                UpdateModel(model);
                jobryrepository.SaveOrEditModel(model);
                return RedirectToAction("index");
            }
            else
                return View("404");
        }
        #endregion
    }

View代码

Index.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.Job>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
             <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                    <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">编号</td>
                        <td class="rgtd2">岗位名称</td>
                        <td class="rgtd3">岗位说明</td>
                        <td class="rgtd3">是否主管</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.JobID</td>
                            <td class="rgtd2">@item.JobName</td>
                            <td class="rgtd3">@item.JobContent</td>
                            <td class="rgtd3">@(item.IsManager == 1 ? "是" : "否")</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/job/delete/@item.JobID">删除</a> | <a href="/job/edit/@item.JobID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
        <div class="rg5">
            @UIHelper.PagesHelper(ViewBag.ControllerName, Model.TotalPages, Model.PageIndex, Model.PageSize, Model.TotalCount, Model.HasPreviousPage, Model.HasNextPage, Model.PageList);
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

Add.cshtml

代码如下:

@{
     ViewBag.Title = "Add";
     Layout = "~/Views/Shared/_Layout.cshtml";
 }
 <div class="contrgcon">
     <div class="rgtit3">
         <div class="tit1">
             <h3>添加</h3>
         </div>
         <div class="rgtit3con">
             @using (Html.BeginForm())
             {
                 <dl>
                     <dd class="dc1">岗位名称:</dd>
                     <dd>
                         <input name="JobName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" />
                     </dd>
                 </dl>
                 <dl>
                     <dd class="dc1">是否主管:</dd>
                     <dd>
                         <select name="IsManager">
                             <option value="1">是</option>
                             <option value="0">否</option>
                         </select>
                     </dd>
                 </dl>
                 <dl>
                     <dd class="dc1">岗位说明:</dd>
                     <dd>
                          <textarea rows="10" cols="82" name="JobContent" id="JobContent"></textarea>
                     </dd>
                 </dl>
                 <dl>
                     <dd>
                         <input type="submit" value="提 交" class="rgbut4" />
                     </dd>
                 </dl>
             }
         </div>
     </div>
 </div>
 <script>
     //菜单显示
     $("#systemusersys").addClass("hbg");
     $("#@(ViewBag.ControllerName)").removeClass("navli");
     $("#@(ViewBag.ControllerName)").addClass("navlihg");
     $(".systemusersys").each(function (index, item) {
         $(this).show();
     });
 </script>

Edit.cshtml

代码如下:

@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Models.Job
<div class="contrgcon">
    <div class="rgtit3">
        <div class="tit1">
            <h3>编辑</h3>
        </div>
        <div class="rgtit3con">
            @using (Html.BeginForm())
            {
                <dl>
                    <dd class="dc1">岗位名称:</dd>
                    <dd>
                        <input name="JobName" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@Model.JobName" />
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">是否主管:</dd>
                    <dd>
                        @UIHelper.IsSelect("IsManager",Model.IsManager.ToString());
                    </dd>
                </dl>
                <dl>
                    <dd class="dc1">岗位说明:</dd>
                    <dd>
                        <textarea rows="10" cols="82" name="JobContent" id="JobContent">@Model.JobContent</textarea>
                    </dd>
                </dl>
                <dl>
                    <dd>
                        <input type="submit" value="提 交" class="rgbut4" />
                    </dd>
                </dl>
            }
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>
@*<script src="/Content/Scripts/Validform_v5.3.2.js"></script>
<script>
    $(document).ready(function () {
        $("#addform").Validform({
            tiptype: 3
        });
    });
</script>*@
<script src="@Url.Content("~/Content/kindeditor/kindeditor-min.js")" type="text/javascript"></script>
@*<script type="text/javascript">
    KindEditor.ready(function (K) {
        K.create('#JobContent', {
            allowFileManager: true
        });
    });
</script>*@

Search.cshtml

代码如下:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SJCRM.Helpers.Pager<SJCRM.Models.Job>
<div class="contrgcon">
    <div class="contrg_list">
        <div class="rgtit">
             <form method="post" action="/@ViewBag.ControllerName/search">
                <dl>
                    <dd>关键词:</dd>
                    <dd>
                        <input name="KeyWord" type="text" class="rgtxt2" /></dd>
                    <dd>
                        <input type="submit" value="查 询" class="rgbut1" /></dd>
                </dl>
            </form>
        </div>
        <div class="rgc">
            <dl class="rgt11">
                <dt>
                    <span class="sple"><a href="/@ViewBag.ControllerName/add">添加</a></span>
                </dt>
            </dl>
            <div class="rg3">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="rgtd2">编号</td>
                        <td class="rgtd2">岗位名称</td>
                        <td class="rgtd3">岗位说明</td>
                        <td class="rgtd3">是否主管</td>
                        <td class="rgtd3">状态</td>
                        <td class="rgtd4">操作</td>
                    </tr>
                </table>
            </div>
            <div class="rg4">
                @{int classnum = 1;}
                @foreach (var item in Model)
                {
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
                                                                                   {<text>class="rgbg2"</text>}>
                        <tr>
                            <td class="rgtd2">@item.JobID</td>
                            <td class="rgtd2">@item.JobName</td>
                            <td class="rgtd3">@item.JobContent</td>
                            <td class="rgtd3">@(item.IsManager == 1 ? "是" : "否")</td>
                            <td class="rgtd3">@(item.State == 1 ? "有效" : "无效")</td>
                            <td class="rgtd4"><a href="/job/delete/@item.JobID">删除</a> | <a href="/job/edit/@item.JobID">编辑</a>  </td>
                        </tr>
                    </table>
                                                                                   classnum = classnum + 1;
                }
            </div>
        </div>
    </div>
</div>
<script>
    //菜单显示
    $("#systemusersys").addClass("hbg");
    $("#@(ViewBag.ControllerName)").removeClass("navli");
    $("#@(ViewBag.ControllerName)").addClass("navlihg");
    $(".systemusersys").each(function (index, item) {
        $(this).show();
    });
</script>

(0)

相关推荐

  • ASP.NET MVC使用ActionFilterAttribute实现权限限制的方法(附demo源码下载)

    本文实例讲述了ASP.NET MVC使用ActionFilterAttribute实现权限限制的方法.分享给大家供大家参考,具体如下: ActionFilterAttribute是Action过滤类,该属于会在执行一个action之前先执行.而ActionFilterAttribute是 MVC的一个专门处理action过滤的类.基于这个原理 我们做一个权限限制 例如:如何访问 HomeController  里的test  action using System; using System.C

  • ASP.NET.4.5.1+MVC5.0设置系统角色与权限(一)

    数据结构 权限分配 1.在项目中新建文件夹Helpers 2.在HR.Helpers文件夹下添加EnumMoudle.Cs 复制代码 代码如下: namespace HR.Helpers {     public enum EnumMoudle     {         /// <summary>         /// 模块         /// </summary>         [EnumTitle("用户管理")]         SysUserM

  • ASP.NET MVC+EF框架+EasyUI实现权限管系列

    前言:本文开始我们便一步一步的来实现这个权限系统的初步设计-框架搭建,首先我要说的是我们需要开发工具Visual Studio 2012或者10也行,其次是我们要有SQL Server数据库,如果是Visual Studio 2010的话,你还要安装MVC4的开发文件,这个是吗?我不记得了,谁可以回答我一下的,我一直用2012,都是集成好的,所以不太清楚.因为这篇博客比较简单,只是建立一个简单的架构,所以我顺便进行一下MVC的知识补充,后面我也会这样穿插着介绍项目中遇到的技术,下面开始今天之旅.

  • asp.net MVC利用ActionFilterAttribute过滤关键字的方法

    本文实例讲述了asp.net MVC利用ActionFilterAttribute过滤关键字的方法.分享给大家供大家参考,具体如下: 在开发过程中,有时候会对用户输入进行过滤,以便保证平台的安全性.屏蔽的方法有很多种,但是今天我说的这种主要是利用MVC中的ActionFilterAttribute属性来实现.由于MVC天然支持AOP,所以我们这种过滤方式正好利用了MVC的这种特性. 下面请看步骤: 首先,当用户输入自己的名称的时候,带有类似<BR>的内容的时候,由于MVC默认是需要验证内容的,

  • ASP.NET MVC 中实现基于角色的权限控制的处理方法

    [Authorize]public ActionResult Index() 标记的方式,可以实现所标记的ACTION必须是认证用户才能访问: 通过使用 [Authorize(Users="username")] 的方式,可以实现所标记的ACTION必须是某个具体的用户才能访问,以上两种方式使用起来非常方便,在NeedDinner示例程序中已有具休的实现过程, 但是,我们在实际的应用中所使用的大都是基于角色(Roles)的认证方式,NeedDinner中却未给出,本文给出具体实现(基于

  • Asp.net Mvc 身份验证、异常处理、权限验证(拦截器)实现代码

    1.用户登录 验证用户是否登录成功步骤直接忽略,用户登录成功后怎么保存当前用户登录信息(session,cookie),本文介绍的是身份验证(其实就是基于cookie)的,下面看看代码. 引入命名空间 using System.Web.Security; 复制代码 代码如下: Users ModelUser = new Users() { ID = 10000, Name = UserName, UserName = UserName, PassWord = PassWord, Roles =

  • 一个基于Asp.Net MVC的权限方案

    1.数据结构Mad_Popedom为权限表,Control记录控制器名,Action记录动作名.Mad_Role为角色表. 2.权限控制的实现此处使用比较简单AOP方式,用MVC的Filter实现,代码如下 复制代码 代码如下: using System.Collections.Generic; using System.Web.Mvc; using Madnet.Model.MadAdmin; using Madnet.BLL.MadAdmin; namespace Madnet.Contro

  • ASP.NET.4.5.1+MVC5.0设置系统角色与权限(二)

    系统角色篇 数据结构 用户管理 Controller代码 复制代码 代码如下: public class SystemUserController : Controller     {         //public void Log()         //{         //    string meg = "";         //    int user = int.Parse(CookieHelper.GetValue("SysUserID"));

  • 使用ASP.NET.4.5.1+MVC5.0 搭建一个包含 Ninject框架 项目

    1.创建一个空白解决方案 2.添加一个类库 名称为XXX.Domain 3.添加一个ASP.MVC名称为XXX.WebUI 4.选着空模版,勾选MVC核心引用 5.添加单元测试项目XXX.UntiTests 6.在程序包控制台里面输入以下代码 复制代码 代码如下: Install-Package Ninject -version 3.0.1.10 -projectname Toad.WebUI Install-Package  Ninject.Web.Common  -version  3.0.

  • 浅谈从ASP.NET Core2.2到3.0你可能会遇到这些问题

    趁着假期的时间所以想重新学习下微软的官方文档来巩固下基础知识.我们都知道微软目前已经发布了.NET Core3.0的第三个预览版,同时我家里的电脑也安装了vs2019.So,就用vs2019+.NET Core3.0来跟着做一下Contoso University这个WEB应用,但是在基于3.0进行操作的时候遇到了一些问题,所以我就查看了微软的<从 ASP.NET Core 迁移 2.2 到 3.0 预览版 2>这篇文档,就着今天遇到的问题,所以我整理下,希望对大伙有所帮助,当然大伙也可以直接

  • ASP.NET在MVC中MaxLength特性设置无效的解决方法

    本文实例讲述了ASP.NET在MVC中MaxLength特性设置无效的解决方法.分享给大家供大家参考.具体分析如下: 一.问题: 在ASP.NET MVC项目中,给某个Model打上了MaxLength特性如下: 复制代码 代码如下: public class SomeClass {     [MaxLength(16, ErrorMessage = "最大长度16")]     public string SomeProperty{get;set;} } 但在其对应的表单元素中并没有

  • Vue2.0设置全局样式(less/sass和css)

    为Vue设置全局样式需要几个步骤(如果是sass将less改成sass即可) 第一步:在src目录下的main.js,也就是入口文件里面添加下面代码 require('!style-loader!css-loader!less-loader!./common/less/index.less') 在Vue1.0版本中可以这样写,但是2.0版本中就不行,会报错提示解析错误 require('./common/less/index.less') 第二步:在build目录下的webpack.base.c

  • Tomcat7.0设置虚拟目录配置虚拟路径的方法讲解

    Tomcat7.0设置虚拟目录 (1)目前,我们的网站站点都是放在默认的目录下:tomcat/webapps/下的.但是,在某种情况下,我们需要把站点放到其他的目录,比如:tomcat所在磁盘的空间不足: 或者为了项目的统一管理,希望放在某个特定的目录下而不是默认的目录. (2)那么我们就是用今天的方法解决这个问题(同样是修改config/server.xml文件): (3)按照下边的图片找到server.xml文件(config-----server.xml记事本打开即可) (4)打开之后拉到

  • android 6.0下webview的定位权限设置方法

    如下所示: WebView webView = (WebView)findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); //webview支持js脚本 webSettings.setJavaScriptEnabled(true); //启用数据库 webSettings.setDatabaseEnabled(true); //设置定位的数据库路径 String dir = this.getAppl

  • Spring Boot 2.0 设置网站默认首页的实现代码

    Spring Boot设置默认首页,方法实验OK如下 附上Application启动代码 /** * @ClassName Application * @Description Spring-Boot website启动类 * @author kevin.tian * @Date 2018-03 * @version 1.0.0 */ @SpringBootApplication @PropertySource(value={ "file:${APP_HOME_CONF}/overpayment

  • ASP.NET WebAPI2复杂请求跨域设置的方法介绍

    ASP.Net Core的跨域设置比较简单  官方都整合了 具体的参见微软官方文档: https://docs.microsoft.com/zh-cn/aspnet/core/security/cors?view=aspnetcore-3.1#ecors 跨域条件 跨域是指的当前资源访问其他资源时发起的http请求由于安全原因(由于同源策略,域名.协议.端口中只要有一个不同就不同源),浏览器限制了这些请求的正常访问,特别需要注意的是这些发生在浏览器中. 解决方法 方法1.web.config文件

随机推荐