asp.net-mvc – ASP.NET MVC 4 Datagrid
发布时间:2020-05-24 00:03:02 所属栏目:asp.Net 来源:互联网
导读:Im新到ASP.NET MVC,并希望做一个简单的页面,使用Entity检索一些数据并将其显示在分页数据网格中. 任何人都可以指出正确的方向或教程等. 它只是一个概念证明,用于检索东西和显示列表. 为此,您可以使用ASP.NET MVC jqGrid. 下面我已经提到了如何实现的示例代码.
|
Im新到ASP.NET MVC,并希望做一个简单的页面,使用Entity检索一些数据并将其显示在分页数据网格中. 任何人都可以指出正确的方向或教程等. 它只是一个概念证明,用于检索东西和显示列表. 解决方法为此,您可以使用ASP.NET MVC jqGrid.下面我已经提到了如何实现的示例代码. 样品图像 行动方法 public ActionResult JsonSalesCollection(DateTime startDate,DateTime endDate,string sidx,string sord,int page,int rows)
{
SalesLogic logicLayer = new SalesLogic();
List<Sale> context;
// If we aren't filtering by date,return this month's contributions
if (startDate == DateTime.MinValue || endDate == DateTime.MinValue)
{
context = logicLayer.GetSales();
}
else // Filter by specified date range
{
context = logicLayer.GetSalesByDateRange(startDate,endDate);
}
// Calculate page index,total pages,etc. for jqGrid to us for paging
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = context.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
// Order the results based on the order passed into the method
string orderBy = string.Format("{0} {1}",sidx,sord);
var sales = context.AsQueryable()
.OrderBy(orderBy) // Uses System.Linq.Dynamic library for sorting
.Skip(pageIndex * pageSize)
.Take(pageSize);
// Format the data for the jqGrid
var jsonData = new
{
total = totalPages,page = page,records = totalRecords,rows = (
from s in sales
select new
{
i = s.Id,cell = new string[] {
s.Id.ToString(),s.Quantity.ToString(),s.Product,s.Customer,s.Date.ToShortDateString(),s.Amount.ToString("c")
}
}).ToArray()
};
// Return the result in json
return Json(jsonData);
}
Jquery设置 <script type="text/javascript">
var gridDataUrl = '/Home/JsonSalesCollection';
// use date.js to calculate the values for this month
var startDate = Date.parse('today').moveToFirstDayOfMonth();
var endDate = Date.parse('today');
jQuery("#list").jqGrid({
url: gridDataUrl + '?startDate=' + startDate.toJSONString() + '&endDate=' + endDate.toJSONString(),datatype: "json",mtype: 'GET',colNames: ['Sale Id','Quantity','Product','Customer','Date','Amount'],colModel: [
{ name: 'Id',index: 'Id',width: 50,align: 'left' },{ name: 'Quantity',index: 'Quantity',width: 100,{ name: 'Product',index: 'Product',{ name: 'Customer',index: 'Customer',{ name: 'Date',index: 'Date',{ name: 'Amount',index: 'Amount',align: 'right'}],rowNum: 20,rowList: [10,20,30],imgpath: gridimgpath,height: 'auto',width: '700',pager: jQuery('#pager'),sortname: 'Id',viewrecords: true,sortorder: "desc",caption: "Sales"
});
</script>
你可以从GridView in ASP.NET MVC Here获得更多的细节 要么 检查这个Get the Most out of WebGrid in ASP.NET MVC(兼容MVC 4) 我希望这将有助于你. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 用于Active Directory帐户的Oauth 2令牌
- asp.net-mvc – 我应该为ASP.Net MVC项目使用什么ORM?
- asp.net – 如何在迭代字典项时更新值?
- .net – 如何在ASP成员资格中使用LogOut
- asp.net-mvc – DDD原理和ASP.NET MVC项目设计
- asp.net-mvc – 没有值的asp.net mvc htmlattribute
- asp.net-core – 如何在Asp.net Core中检测会话超时?
- .net – HttpContext.Request和Request之间的区别
- NHibernate中关于Inverse的理解和使用
- asp.net“记住我”的cookie
推荐文章
站长推荐
- asp.net – 在Selectedindexchanged事件中选择下
- asp.net-mvc-3 – 在Post上,下拉列表SelectList.
- asp.net-mvc – 如何为MVC4配置Ninject并提供自定
- asp.net – 什么是global.asax用于?
- asp.net-mvc-3 – 为什么_ViewStart.cshtml访问V
- asp.net – 如何防止Azure网站进入睡眠状态?
- asp.net – 提供的URI方案’https’无效;预期’h
- 从ASP.NET MVC应用程序中的Amazon SES发送电子邮
- asp.net – 如何在mvc3中对来自@ Html.LabelFor(
- 如何从ASP.NET Web服务生成JSONP以进行跨域调用?
热点阅读
