asp.net-mvc – 添加分页MVC和Azure表存储
|
我试图将分页应用到我的MVC应用程序中.我使用Azure表存储 这是我尝试过的: – public List<T> GetPagination(string partitionKey,int start,int take)
{
List<T> entities = new List<T>();
TableQuery<T> query = new TableQuery<T>().Where(TableQuery.GenerateFilterCondition("PartitionKey",QueryComparisons.Equal,partitionKey.ToLower()));
entities = Table.ExecuteQuery(query).Skip(start).Take(take).ToList();
return entities;
}
控制器: – public ActionResult Index()
{
key= System.Web.HttpContext.Current.Request[Constants.Key];
if (String.IsNullOrEmpty(key))
return RedirectToAction("NoContext","Error");
var items= _StorageHelper.GetPagination(key,3);
ItemCollection itemCollection = new ItemCollection();
itemCollection .Items= Mapper.Map<List<ItemChart>,List<ItemModel>>(items);
itemCollection .Items.ForEach(g => g.Object = g.Object.Replace(key,""));
return View(itemCollection);
}
这当前给了我数据中的前3个条目.现在,我如何显示和实现“上一页”和“下一页”以显示下一页上的其他条目?如何实现控制器和HTML页面的其余部分? 任何帮助表示赞赏. 解决方法在分页时,需要考虑以下几点:> Table Service不支持所有LINQ运算符(以及OData查询选项).例如,不支持Skip.有关支持的操作符列表,请参阅此链接:https://msdn.microsoft.com/en-us/library/azure/dd135725.aspx. 考虑到这两个因素,您无法真正实现寻呼解决方案,用户可以直接跳转到特定页面(例如,用户坐在第1页,然后用户无法转到第4页).您最多可以实现下一页,上一页和第一页功能. 要实现下一页的功能,请存储表服务返回的延续令牌,并在查询中使用该令牌. 要实现以前页面类型的功能,必须存储在数组或其他内容中返回的所有连续标记,并跟踪用户当前所在的页面(即当前页面索引).当用户想要转到上一页时,您只需获取上一个索引的延续令牌(即当前页面索引 – 1)并在查询中使用它. 要实现第一页类型的功能,只需在没有延续令牌的情况下发出查询. 如果要实现分页,请查看Storage Client Library中的 UPDATE 请参阅下面的示例代码.为简单起见,我只保留了第一页和下一页的功能: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using Microsoft.WindowsAzure.Storage.Table;
namespace TablePaginationSample
{
class Program
{
static string accountName = "";
static string accountKey = "";
static string tableName = "";
static int maxEntitiesToFetch = 10;
static TableContinuationToken token = null;
static void Main(string[] args)
{
var cloudStorageAccount = new CloudStorageAccount(new StorageCredentials(accountName,accountKey),true);
var cloudTableClient = cloudStorageAccount.CreateCloudTableClient();
var table = cloudTableClient.GetTableReference(tableName);
Console.WriteLine("Press "N" to go to next pagenPress "F" to go first pagenPress any other key to exit program");
var query = new TableQuery().Take(maxEntitiesToFetch);
var continueLoop = true;
do
{
Console.WriteLine("Fetching entities. Please wait....");
Console.WriteLine("-------------------------------------------------------------");
var queryResult = table.ExecuteQuerySegmented(query,token);
token = queryResult.ContinuationToken;
var entities = queryResult.Results;
foreach (var entity in entities)
{
Console.WriteLine(string.Format("PartitionKey = {0}; RowKey = {1}",entity.PartitionKey,entity.RowKey));
}
Console.WriteLine("-------------------------------------------------------------");
if (token == null)//No more token available. We've reached end of table
{
Console.WriteLine("All entities have been fetched. The program will now terminate.");
break;
}
else
{
Console.WriteLine("More entities available. Press "N" to go to next page or Press "F" to go first page or Press any other key to exit program.");
Console.WriteLine("-------------------------------------------------------------");
var key = Console.ReadKey();
switch(key.KeyChar)
{
case 'N':
case 'n':
continue;
case 'F':
case 'f':
token = null;
continue;
default:
continueLoop = false;
break;
}
}
} while (continueLoop);
Console.WriteLine("Press any key to terminate the application.");
Console.ReadLine();
}
}
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – UserControl属性中的默认值
- asp.net – 为VS2010和TFS中的团队管理web.config
- asp.net-mvc – 如何从验证摘要中删除列表
- asp.net-mvc – 为什么我的View不包括_Layout.cshtml?
- asp.net 自动将汉字转换成拼音第一个字母
- asp.net – 使用ASP:文本框作为
- .net – RegularExpressionValidator使用除Regex之外的其他
- asp.net-mvc – 发布重定向到ASP.NET MVC和验证与Restful U
- asp.net – 超过了JavaScriptSerializer.MaxJsonLength.处理
- 高性能ASP.NET站点( 1000请求/秒)
- 如何获取基于PhoneGap的应用程序来对ASP.NET For
- asp.net – 如何访问嵌套母版页中的控件?为什么
- 当使用SignalR和传输模式长轮询时,Asp.net会话永
- 在加载asp.net页面时显示gif
- asp.net-mvc – 在ASP.NET MVC中为URL段添加ID和
- asp.net – 使用区域时,“路由表中没有路由匹配提
- 如何通过ASP.NET中的另一个下拉列表过滤下拉列表
- wcf – SOAP API HTTPS – 与经典ASP连接
- asp.net-mvc – Asp.Net Mvc – Html.TextBox –
- asp.net-web-api2 – Swagger中的数据注释
