PagedList.MVC 어플리케이션
2. View Page
@model PagedList.IPagedList<Libaray.Models.Entities.BookModel>
@using PagedList.Mvc;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
$(function () {
$("#txtSearch").val(@Request.QueryString["keyWords"]);
})
</script>
<div class="row" style="margin-top:20px;">
<div class="col-sm-2">
@Html.Partial("_AccountNavigator")
</div>
<div class="col-sm-10">
<div class="row">
<div class="col-sm-6">
<a class="btn btn-sm btn-primary" href="/Book/NewBook"> </a>
</div>
<div class="col-sm-6 ">
<form id="formSearch" method="get" class="form-horizontal">
<div class="input-group text-right">
@Html.TextBox("keyWords",ViewBag.KeyWords as string, new { @name= "keyWords",@class = "form-control", @placeholder = " / / ..." })
<div class="input-group-btn">
<button id="search" class="btn btn-sm btn-primary"> </button>
</div>
</div>
</form>
</div>
</div>
<hr />
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(m => item.BookName)</td>
<td>@Html.DisplayFor(m => item.Author)</td>
<td>@Html.DisplayFor(m => item.BookDescription)</td>
<td>@Html.DisplayFor(m => item.BookDate)</td>
<td>@Html.DisplayFor(m => item.CreatedOn)</td>
<td><a href="/Book/[email protected]"> </a></td>
</tr>
}
</tbody>
</table>
@Html.PagedListPager(Model, id => Url.Action("BookList", new { id,keyWords=ViewBag.KeyWords }))
</div>
</div>
</div>
2. Book Controller
// GET: Book
public ActionResult BookList(int id=1,int irowCount=25, string keyWords =null)
{
BookService BookDAL = new BookService();
ViewBag.KeyWords = keyWords;
var sResult = BookDAL.SearchBookList(id, irowCount, keyWords);
return View(sResult);
}
public class BookService:BaseService<BookModel> // Cache, ,
{
public IPagedList<BookModel> SearchBookList(int id = 1, int irowCount=20, string sKeyWords = null)
{
List<BookModel> sList = new List<BookModel>();
if (WebCacheHelper.GetCache("BookList") == null)
{
using (LibContext = new LibarayContext())
{
sList = LibContext.BookModels.ToList();
WebCacheHelper.SetCache("BookList", sList);
}
}
else
{
sList = WebCacheHelper.GetCache("BookList") as List<BookModel>;
}
if (!string.IsNullOrEmpty(sKeyWords))
{
var squery = from bk in sList where bk.Author.Contains(sKeyWords) || bk.BookName.Contains(sKeyWords) || bk.BookDescription.Contains(sKeyWords) select bk; // , Author, BookName, Description null, 。
return squery.OrderByDescending(u => u.UpdatedOn).ToPagedList(id, irowCount);
}
else
{
return sList.OrderByDescending(m => m.UpdatedOn).ToPagedList(id, irowCount);
}
}
}
WebCacheHelper//다른 사람을 옮겨 싣고 출처를 잊어버렸습니다.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace Libaray.Common
{
public class WebCacheHelper
{
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
/// <param name="CacheKey"> </param>
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
/// <summary>
///
/// </summary>
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
}
/// <summary>
///
/// </summary>
public static void SetCache(string CacheKey, object objObject, TimeSpan Timeout)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
}
/// <summary>
///
/// </summary>
public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
}
/// <summary>
///
/// </summary>
public static void RemoveAllCache(string CacheKey)
{
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
_cache.Remove(CacheKey);
}
/// <summary>
///
/// </summary>
public static void RemoveAllCache()
{
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
_cache.Remove(CacheEnum.Key.ToString());
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.