欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET?MVC5網(wǎng)站開(kāi)發(fā)顯示文章列表(九)

 更新時(shí)間:2022年05月08日 14:08:00   投稿:lijiao  
顯示文章列表分兩塊,管理員可以顯示全部文章列表,一般用戶只顯示自己的文章列表。文章列表的顯示采用easyui-datagrid,后臺(tái)需要與之對(duì)應(yīng)的action返回json類(lèi)型數(shù)據(jù),感興趣的小伙伴們可以參考一下

老習(xí)慣,先上個(gè)效果圖:

1、在IBLL

在InterfaceCommonModelService接口中添加獲取公共模型列表的方法
首先排序方法

/// <summary>
  /// 排序
  /// </summary>
  /// <param name="entitys">數(shù)據(jù)實(shí)體集</param>
  /// <param name="roderCode">排序代碼[默認(rèn):ID降序]</param>
  /// <returns></returns>
  IQueryable<CommonModel> Order(IQueryable<CommonModel> entitys, int roderCode);
查詢數(shù)據(jù)方法
/// <summary>
  /// 查詢分頁(yè)數(shù)據(jù)列表
  /// </summary>
  /// <param name="totalRecord">總記錄數(shù)</param>
  /// <param name="model">模型【All全部】</param>
  /// <param name="pageIndex">頁(yè)碼</param>
  /// <param name="pageSize">每頁(yè)記錄數(shù)</param>
  /// <param name="title">標(biāo)題【不使用設(shè)置空字符串】</param>
  /// <param name="categoryID">欄目ID【不使用設(shè)0】</param>
  /// <param name="inputer">用戶名【不使用設(shè)置空字符串】</param>
  /// <param name="fromDate">起始日期【可為null】</param>
  /// <param name="toDate">截止日期【可為null】</param>
  /// <param name="orderCode">排序碼</param>
  /// <returns>分頁(yè)數(shù)據(jù)列表</returns>
  IQueryable<CommonModel> FindPageList(out int totalRecord, int pageIndex, int pageSize, string model, string title, int categoryID, string inputer, Nullable<DateTime> fromDate, Nullable<DateTime> toDate, int orderCode);

2、BLL

在CommonModelService寫(xiě)方法實(shí)現(xiàn)代碼,內(nèi)容都很簡(jiǎn)單主要是思路,直接上代碼

public IQueryable<CommonModel> FindPageList(out int totalRecord, int pageIndex, int pageSize, string model, string title, int categoryID, string inputer, Nullable<DateTime> fromDate, Nullable<DateTime> toDate, int orderCode)
  {
   //獲取實(shí)體列表
   IQueryable<CommonModel> _commonModels = CurrentRepository.Entities;
   if (model == null || model != "All") _commonModels = _commonModels.Where(cm => cm.Model == model);
   if (!string.IsNullOrEmpty(title)) _commonModels = _commonModels.Where(cm => cm.Title.Contains(title));
   if (categoryID > 0) _commonModels = _commonModels.Where(cm => cm.CategoryID == categoryID);
   if (!string.IsNullOrEmpty(inputer)) _commonModels = _commonModels.Where(cm => cm.Inputer == inputer);
   if (fromDate != null) _commonModels = _commonModels.Where(cm => cm.ReleaseDate >= fromDate);
   if (toDate != null) _commonModels = _commonModels.Where(cm => cm.ReleaseDate <= toDate);
   _commonModels = Order(_commonModels, orderCode);
   totalRecord = _commonModels.Count();
   return PageList(_commonModels, pageIndex, pageSize).AsQueryable();
  }

  public IQueryable<CommonModel> Order(IQueryable<CommonModel> entitys, int orderCode)
  {
   switch(orderCode)
   {
    //默認(rèn)排序
    default:
     entitys = entitys.OrderByDescending(cm => cm.ReleaseDate);
     break;
   }
   return entitys;
  }

3、web

由于CommonModel跟我們前臺(tái)顯示的數(shù)據(jù)并不一致,為了照顧datagrid中的數(shù)據(jù)顯示再在Ninesky.Web.Models中再構(gòu)造一個(gè)視圖模型CommonModelViewModel

using System;

namespace Ninesky.Web.Models
{
 /// <summary>
 /// CommonModel視圖模型
 /// <remarks>
 /// 創(chuàng)建:2014.03.10
 /// </remarks>
 /// </summary>
 public class CommonModelViewModel
 {
  public int ModelID { get; set; }

  /// <summary>
  /// 欄目ID
  /// </summary>
  public int CategoryID { get; set; }

  /// <summary>
  /// 欄目名稱(chēng)
  /// </summary>
  public string CategoryName { get; set; }

  /// <summary>
  /// 模型名稱(chēng)
  /// </summary>
  public string Model { get; set; }

  /// <summary>
  /// 標(biāo)題
  /// </summary>
  public string Title { get; set; }

  /// <summary>
  /// 錄入者
  /// </summary>
  public string Inputer { get; set; }

  /// <summary>
  /// 點(diǎn)擊
  /// </summary>
  public int Hits { get; set; }

  /// <summary>
  /// 發(fā)布日期
  /// </summary>
  public DateTime ReleaseDate { get; set; }

  /// <summary>
  /// 狀態(tài)
  /// </summary>
  public int Status { get; set; }

  /// <summary>
  /// 狀態(tài)文字
  /// </summary>
  public string StatusString { get { return Ninesky.Models.CommonModel.StatusList[Status]; } }

  /// <summary>
  /// 首頁(yè)圖片
  /// </summary>
  public string DefaultPicUrl { get; set; }
 }
}

在ArticleController中添加一個(gè)返回json類(lèi)型的JsonList方法

/// <summary>
  /// 文章列表Json【注意權(quán)限問(wèn)題,普通人員是否可以訪問(wèn)?】
  /// </summary>
  /// <param name="title">標(biāo)題</param>
  /// <param name="input">錄入</param>
  /// <param name="category">欄目</param>
  /// <param name="fromDate">日期起</param>
  /// <param name="toDate">日期止</param>
  /// <param name="pageIndex">頁(yè)碼</param>
  /// <param name="pageSize">每頁(yè)記錄</param>
  /// <returns></returns>
  public ActionResult JsonList(string title, string input, Nullable<int> category, Nullable<DateTime> fromDate, Nullable<DateTime> toDate, int pageIndex = 1, int pageSize = 20)
  {
   if (category == null) category = 0;
   int _total;
   var _rows = commonModelService.FindPageList(out _total, pageIndex, pageSize, "Article", title, (int)category, input, fromDate, toDate, 0).Select(
    cm => new Ninesky.Web.Models.CommonModelViewModel() 
    { 
     CategoryID = cm.CategoryID,
     CategoryName = cm.Category.Name,
     DefaultPicUrl = cm.DefaultPicUrl,
     Hits = cm.Hits,
     Inputer = cm.Inputer,
     Model = cm.Model,
     ModelID = cm.ModelID,
     ReleaseDate = cm.ReleaseDate,
     Status = cm.Status,
     Title = cm.Title 
    });
   return Json(new { total = _total, rows = _rows.ToList() });
  }

下面是做界面了,在添加 List方法,這里不提供任何數(shù)據(jù),數(shù)據(jù)在JsonList 中獲得

/// <summary>
  /// 全部文章
  /// </summary>
  /// <returns></returns>
  public ActionResult List()
  {
   return View();
  }

右鍵添加視圖

<div id="toolbar">
 <div>
  <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" >修改</a>
  <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" ">刪除</a>
  <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="$('#article_list').datagrid('reload');">刷新</a>
 </div>
 <div class="form-inline">
  <label>欄目</label><input id="combo_category" data-options="url:'@Url.Action("JsonTree", "Category", new { model="Article" })'" class="easyui-combotree" />
  <label>標(biāo)題</label> <input id="textbox_title" class="input-easyui" style="width:280px" />
  <label>錄入人</label><input id="textbox_inputer" class="input-easyui" />
  <label>添加日期</label>
  <input id="datebox_fromdate" type="datetime" class="easyui-datebox" style="width:120px" /> -
  <input id="datebox_todate" type="datetime" class="easyui-datebox" style="width:120px; " />
  <a href="#" id="btn_search" data-options="iconCls:'icon-search'" class="easyui-linkbutton">查詢</a>
 </div>

</div>
<table id="article_list"></table>
<script src="~/Scripts/Common.js"></script>
<script type="text/javascript">
 $("#article_list").datagrid({
  loadMsg: '加載中……',
  pagination:true,
  url: '@Url.Action("JsonList","Article")',
  columns: [[
   { field: 'ModelID', title: 'ID', checkbox: true },
   { field: 'CategoryName', title: '欄目'},
   { field: 'Title', title: '標(biāo)題'},
   { field: 'Inputer', title: '錄入', align: 'right' },
   { field: 'Hits', title: '點(diǎn)擊', align: 'right' },
   { field: 'ReleaseDate', title: '發(fā)布日期', align: 'right', formatter: function (value, row, index) { return jsonDateFormat(value); } },
   { field: 'StatusString', title: '狀態(tài)', width: 100, align: 'right' }
  ]],
  toolbar: '#toolbar',
  idField: 'ModelID',
 });
 //查找
 $("#btn_search").click(function () {
  $("#article_list").datagrid('load', {
   title: $("#textbox_title").val(),
   input: $("#textbox_inputer").val(),
   category: $("#combo_category").combotree('getValue'),
   fromDate: $("#datebox_fromdate").datebox('getValue'),
   toDate: $("#datebox_todate").datebox('getValue')
  });
 });

 }
</script>

上面都是easyui-datagrid的內(nèi)容。

總體思路是BLL中實(shí)現(xiàn)查詢公共模型列表,web中添加一個(gè)JsonList方法調(diào)用BLL中的方法并返回列表的Json類(lèi)型。然后再添加一個(gè)List調(diào)用JsonList用來(lái)顯示。下篇文章做刪除和修改操作,希望大家會(huì)持續(xù)關(guān)注。

相關(guān)文章

  • WPF氣泡樣式彈窗效果代碼分享

    WPF氣泡樣式彈窗效果代碼分享

    這篇文章主要為大家詳細(xì)介紹了WPF氣泡樣式彈窗效果的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • asp.net datalist 用法

    asp.net datalist 用法

    asp.net datalist 用法,需要的朋友可以參考下。
    2009-08-08
  • .NET Core 3.0中WPF使用IOC的圖文教程

    .NET Core 3.0中WPF使用IOC的圖文教程

    這篇文章主要給大家介紹了關(guān)于在.NET Core 3.0中WPF使用IOC的圖文教程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • asp.net+ajax的Post請(qǐng)求實(shí)例

    asp.net+ajax的Post請(qǐng)求實(shí)例

    這篇文章主要介紹了asp.net+ajax的Post請(qǐng)求實(shí)現(xiàn)方法,實(shí)例分析了Ajax的發(fā)送post數(shù)據(jù)的原理與技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • asp.net發(fā)郵件的幾種方法匯總

    asp.net發(fā)郵件的幾種方法匯總

    .net中發(fā)送郵件方法有很多,如MailMessage,SmtpMail等下面我來(lái)給大家利用這些方法來(lái)實(shí)現(xiàn)在.net中郵件發(fā)送吧,希望此方法對(duì)各位同學(xué)會(huì)有所幫助
    2014-01-01
  • Asp.Net Core中發(fā)送Email的完整步驟

    Asp.Net Core中發(fā)送Email的完整步驟

    這篇文章主要給大家介紹了關(guān)于Asp.Net Core中發(fā)送Email的完整步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • asp.net下實(shí)現(xiàn)支持文件分塊多點(diǎn)異步上傳的 Web Services

    asp.net下實(shí)現(xiàn)支持文件分塊多點(diǎn)異步上傳的 Web Services

    asp.net下實(shí)現(xiàn)支持文件分塊多點(diǎn)異步上傳的 Web Services...
    2007-04-04
  • ASP.NET MVC中使用Bundle打包壓縮js和css的方法

    ASP.NET MVC中使用Bundle打包壓縮js和css的方法

    這篇文章主要為大家詳細(xì)介紹了ASP.NET MVC中使用Bundle打包壓縮js和css的方法,感興趣的小伙伴們可以參考一下
    2016-05-05
  • 三種方法讓Response.Redirect在新窗口打開(kāi)

    三種方法讓Response.Redirect在新窗口打開(kāi)

    通過(guò)設(shè)置form的target屬性同樣可以讓Response.Rederect所指向的url在新的窗口打開(kāi),下面為大家介紹三種具體的實(shí)現(xiàn)方法
    2013-10-10
  • 運(yùn)用.net core中實(shí)例講解RabbitMQ高可用集群構(gòu)建

    運(yùn)用.net core中實(shí)例講解RabbitMQ高可用集群構(gòu)建

    這篇文章主要介紹了運(yùn)用.net core中實(shí)例講解RabbitMQ高可用集群構(gòu)建,文中相關(guān)示例代碼講解的非常清晰,感興趣的小伙伴可以參考一下這篇文章,相信可以幫助到你
    2021-09-09

最新評(píng)論