ASP.NET MVC5网站开发之用户添加和浏览2(七)(5)

ASP.NET MVC5网站开发之用户添加和浏览2(七)

1、用户浏览

1.1、分页列表方法

在UserController中添加方法PageListJson,返回Json格式的分页数据。

/// <summary> /// 分页列表【json】 /// </summary> /// <param>角色ID</param> /// <param>用户名</param> /// <param>名称</param> /// <param>性别</param> /// <param>Email</param> /// <param>页码</param> /// <param>每页记录数</param> /// <param>排序</param> /// <returns>Json</returns> public ActionResult PageListJson(int? roleID, string username,string name,int? sex,string email,int? pageNumber, int? pageSize,int? order) { Paging<User> _pagingUser = new Paging<Core.User>(); if (pageNumber != null && pageNumber > 0) _pagingUser.PageIndex = (int)pageNumber; if (pageSize != null && pageSize > 0) _pagingUser.PageSize = (int)pageSize; var _paging = userManager.FindPageList(_pagingUser, roleID, username, name, sex, email, null); return Json(new { total = _paging.TotalNumber, rows = _paging.Items }); }

1.2、默认页视图

在UserController中添加Index方法

/// <summary> /// 默认页 /// </summary> /// <returns></returns> public ActionResult Index() { return View(); }

在Index 方法上点右键 –>添加->视图

ASP.NET MVC5网站开发之用户添加和浏览2(七)

@{ ViewBag.Title = "用户管理"; } @section SideNav{@Html.Partial("SideNavPartialView")} <ol> <li><span></span> @Html.ActionLink("首页", "Index", "Home")</li> <li>@Html.ActionLink("用户管理", "Index", "User")</li> </ol> <table></table> @section style{ @Styles.Render("~/Content/bootstrapplugincss") } @section scripts{ @Scripts.Render("~/bundles/jqueryval") @Scripts.Render("~/bundles/bootstrapplugin") <script type="text/javascript"> $(document).ready(function () { //表格 var $table = $('#usergrid'); $table.bootstrapTable({ showRefresh: true, showColumns: true, pagination: true, sidePagination: "server", pageList:"[5, 10, 20, 50, 100]", method: "post", url: "https://www.jb51.net/@Url.Action("PageListJson")", columns: [ { title: "ID", field: "UserID" }, { title: "角色", field: "RoleID" }, { title: "用户名", field: "Username" }, { title: "名称", field: "Name", formatter: function (value, row, index) { return "<a href='@Url.Action("Modify", "User")/" + row.UserID + "'>" + value + "</a>" } }, { title: "性别", field: "Sex" }, { title: "Email", field: "Email", visible:false }, { title: "最后登录时间", field: "LastLoginTime" }, { title: "最后登录IP", field: "LastLoginIP", visible:false }, { title: "注册时间", field: "RegTime",visible:false }, { title: "操作", field: "UserID", formatter: function (value) { return "<a data-operation='deleteuser' data-value='" + value + "'>删除</a>" } } ], onLoadSuccess: function () { //删除按钮 //删除按钮结束 } }); //表格结束 }); </script> }

1.3侧导航局部视图

Ninesky.Web/Areas/Control/Views/User【右键】->添加->视图,输入视图名称

ASP.NET MVC5网站开发之用户添加和浏览2(七)

<div> <div> <div><span></span> 用户管理</div> </div> <div> <div> <div><span></span> @Html.ActionLink("添加用户", "Add", "User")</div> <div><span></span> @Html.ActionLink("用户管理", "Index", "User")</div> </div> </div> </div>

2、添加用户

2.1 添加用户视图模型

Ninesky.Web/Areas/Control/Models【右键】->添加->“AddUserViewModel”

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjyjpf.html