bootstrap adminlte教程10:问答系统的ClubContents的首页的方法
这个首页的内容就多了,很多个方法,直接上图
这个里面的内涵太多了,我干了整整一天才学会。
1)先读出来,按降序。然后顺利的实现 个样式。
2)实现上面的菜单,未完成,完成,全部,然后下拉(这个复杂),还有搜索等。
未完成是默认的,完成的就是送一个?ClubStae=1.
全部就是不要Where(ClubStae)
搜索,就包含这个TITLE。
3)回复完了还要给COUNT+1
4)管理员,可以看到DEL (删除)和OK(强制完结)
5)分页功能
现在上代码控制器
// GET: ClubContents public ActionResult Index(string ClubState, string listColumn, string SearchString, int? page) { //读出所有的栏目到表中 ViewBag.drolistmenu = db.CmsColumns.Where(x => x.ColumnType == "2"); ///当没有字符串产生的时候,为PAGE1 if ( !string.IsNullOrEmpty(ClubState) && !string.IsNullOrEmpty(SearchString) && !string.IsNullOrEmpty(listColumn)) { page = 1; } ViewBag.listColumn = listColumn; ViewBag.ClubState = ClubState; ViewBag.SearchString = SearchString; ///获取数据,我们默认显示未完结 var seachindex = from w in db.ClubContents.OrderByDescending(c => c.CreatTime).Where(m => m.ReplyID == null).Where(x => x.ClubState == "0") select w; //再次分析栏目 ///首先看栏目变量是否为空 if (!string.IsNullOrEmpty(listColumn)) { int clounid = int.Parse(listColumn); if (ClubState == "1") { seachindex = from l in db.ClubContents.OrderByDescending(q => q.CreatTime).Where(m => m.ReplyID == null).Where(x => x.ClubState == "1").Where(p => p.ColumnId == clounid) select l; } else { seachindex = from l in db.ClubContents.OrderByDescending(c => c.CreatTime).Where(m => m.ReplyID == null).Where(x => x.ClubState == "0").Where(k => k.ColumnId == clounid) select l; } } else { if (ClubState == "1") { seachindex = from x in db.ClubContents.OrderByDescending(c => c.CreatTime).Where(m => m.ReplyID == null).Where(x => x.ClubState == "1") select x; } if (ClubState == "all") { seachindex = from x in db.ClubContents.OrderByDescending(c => c.CreatTime).Where(m => m.ReplyID == null) select x; } } //搜索,如是搜索字符串不为空,则取消所有的,只取Title包含有,同时降序 if (!string.IsNullOrEmpty(SearchString)) { seachindex = from x in db.ClubContents.OrderByDescending(c => c.CreatTime).Where(m => m.ReplyID == null).Where(x => x.Title.Contains(SearchString)) select x; } int pageNumber = page ?? 1; int pageSize =8; //通过ToPagedList扩展方法进行分页 //IPagedList<CmsContent> pagedList = seachindex.ToPagedList(pageNumber, pageSize); return View(seachindex.ToPagedList(pageNumber, pageSize)); }
2.视图
@model PagedList.IPagedList<jsdhh2.Models.ClubContent> @using PagedList.Mvc; <link href="~/Content/PagedList.css" rel="stylesheet" /> @{ ViewBag.Title = "Index"; } <!-- Content Header (Page header) --> <section class="content-header"> <p>.</p> <h1> 支撑中心 <small>你问我答,爽得很!</small> </h1> <ol class="breadcrumb"> <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li> <li class="active">Here</li> </ol> </section> <!--end Content Header (Page header) --> <section class="content"> <!--start button --> <h2></h2> <div class="btn-group text-right col-md-7 col-xs-12" role="group" aria-label="..."> <a class="btn btn-info" href="/ClubContents" role="button">未完结</a> <a class="btn btn-default" href="/ClubContents/Index?ClubState=1" role="button">已完结</a> <a class="btn btn-default" href="/ClubContents/Index?ClubState=all" role="button">全部</a> <div class="btn-group" role="group"> <button type="button" class="btn btn-warning dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 栏目未完结 <span class="caret"></span> </button> <ul class="dropdown-menu"> @foreach (jsdhh2.Models.CmsColumn data in (ViewBag.drolistmenu as IEnumerable<jsdhh2.Models.CmsColumn>)) { <li><a href="/ClubContents/Index?listColumn=@data.Id">@data.Name</a></li> } </ul> </div> <div class="btn-group" role="group"> <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 栏目已完结 <span class="caret"></span> </button> <ul class="dropdown-menu"> @foreach (jsdhh2.Models.CmsColumn data in (ViewBag.drolistmenu as IEnumerable<jsdhh2.Models.CmsColumn>)) { <li><a href="/ClubContents/Index?ClubState=1&&listColumn=@data.Id">@data.Name</a></li> } </ul> </div> </div> <div class="col-md-4 col-xs-8 text-right"> @using (Html.BeginForm("index", "ClubContents", new { @class = "form-inline" }, FormMethod.Post)) { <div class="form-inline"> <div class="form-group"> <div class="input-group"> @Html.TextBox("SearchString", "", new { @class = "form-control", @Style = "display:inline" }) <span class="input-group-btn "> <input id="btnSearch" class="btn btn btn-primary" type="submit" value="搜索"> </span> </div> </div> </div> } </div> <div class="col-md-1 col-xs-4 text-left"><a class="btn btn-success" href="~/ClubContents/Create" role="button">发布问题</a></div> <p>.</p> <!--end button --> <!--开始foreach显示--> <h2></h2> @foreach (var item in Model) { <div class="detail-about "> <div class="col-md-1 col-xs-3"> <img src=@Html.DisplayFor(modelItem => item.ClubHeadPic) class="img-circle" style="width: 46px; height: 46px;"> </div> <a href="">@Html.DisplayFor(modelItem => item.CreatUser) </a> <span style="color:#c7c2c2;">发表于:@Html.DisplayFor(modelItem => item.CreatTime)</span> 回复:<span class="badge">@Html.DisplayFor(modelItem => item.ReplyCount)</span> <br style="padding-left:90px; margin-top:-20px;"> IP地址: @Html.DisplayFor(modelItem => item.PcIp); <a class="btn btn-success btn-sm" href="~/ClubContents/CreateRlpy?Id=@item.Id" role="button">我要回复</a> </div> <div class="row"> <div class="col-md-1 col-xs-3"> <h5></h5> <small> @if (item.ClubState == "1") { <span class="label label-default">完结</span> } else {<span class="label label-default">未完结</span> } </small> </div><h4>@Html.DisplayFor(modelItem => item.Title)</h4> </div> <div class="clubtentext img-responsive"> @*@Html.DisplayFor(model => model.Contents)*@ @Html.Raw(item.Contents) </div> <div class="right"> <div class="row"> <div class="col-md-2 col-xs-6">@Html.ActionLink("查看全文...", "Details", new { id = item.Id }) |</div> <div class="text-right"> @if (Session["role"].ToString() == "Super") { <form action="/ClubContents/DelClub?Id=@item.Id" method="post" class="col-md-9 col-xs-3 text-right"> <input id="DelSubmit" class="btn btn-xs btn-warning" type="submit" value="Del"> </form> <form action="/ClubContents/OkClub?Id=@item.Id" method="post" class="col-md-1 col-xs-3 text-left"> <input id="DelSubmit1" class="btn btn-xs btn-info" type="submit" value="Ok"> </form> } </div> </div> </div> } <hr /> Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount @Html.PagedListPager(Model, page => Url.Action("Index", new { page, ClubState = ViewBag.ClubState, listColumn = ViewBag.listColumn, SearchString = ViewBag.SearchString })) <!-- Main content --> </section> @section Scripts { <script type="text/javascript"> window.onload = function () { var bt = document.getElementById("DelSubmit"); bt.onclick = function () { confirm("真的要删除吗?"); } } </script> <script type="text/javascript"> window.onload = function () { var bt = document.getElementById("DelSubmit1"); bt.onclick = function () { confirm("确定完结吗?"); } } </script> }
最难的全部完了,我为了前后分离,重新建了修改资料,将文章的管理又新建了个MyIndex方法和视图,内容一样,只是加上了CreateUserName==我。
只能看到本人的。
然后进行了菜单重新管理,除了Super,其他人暂时只能看见:CMS管理和下面的新建文章,我的文章三个菜单。