@model MvcEasyUIDemo.Models.Products@{ ViewBag.Title = "產品管理";}<script src="~/Scripts/jquery.easyui.min.js"></script>@Scripts.Render("~/bundles/home")@Styles.Render("~/Content/HomeCss")<style> #dlg { padding:5px; } #dlg .format{ margin:15px; } #dlg .format input{ border-radius:3px; margin-left:10px; }</style><h2>產品管理</h2><table id="dg"></table><div id="dg-button"> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="Reload()">刷新</a> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="Add()">添加</a> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="Edit()">修改</a> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="Delete()">刪除</a> <div id="dg-search"> <label for="Name">查詢:</label> <input id="Name" class="easyui-validatebox" data-options="width:200" /> <select id="order" class="easyui-combobox" data-options="width:100"> <option value="asc">升序</option> <option value="desc">降序</option> </select> <a class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="Search()">查詢</a> </div></div><div id="dlg" class="easyui-dialog" data-options="closed:true,title:'產品',buttons:'#dlg-button'"> <form id="dlg-form"> <div class="format"> <label for="ProductID">編  號</label> <input id="ProductID" name="ProductID" class="easyui-validatebox" data-options="required:false" /> </div> <div class="format"> <label for="Name">產品名稱</label> <input id="Name" name="Name" class="easyui-validatebox" data-options="required:true" /> </div> <div class="format"> <label for="Description">描  述</label> <input id="Description" name="Description" class="easyui-validatebox" data-options="required:true" /> </div> <div class="format"> <label for="Category">品  類</label> <input id="Category" name="Category" class="easyui-validatebox" data-options="required:true" /> </div> <div class="format"> <label for="Price">價  格</label> <input id="Price" name="Price" class="easyui-validatebox" data-options="required:true" /> </div> </form> <div id="dlg-button"> <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="Save()">保存</a> <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="JavaScript:$('#dlg').dialog('close')">取消</a> </div></div>
@Scripts.Render("~/bundles/home")@Styles.Render("~/Content/HomeCss")
bundles.Add(new ScriptBundle("~/bundles/home").Include( "~/Scripts/home.js"));bundles.Add(new StyleBundle("~/Content/HomeCss").Include( "~/Content/themes/icon.css", "~/Content/themes/default/easyui.css"));
$(function () { $("#dg").datagrid({ title: '產品管理', url: 'Home/GetProductList', columns: [[ { field: 'ProductID', title: 'ID', width: 150 }, { field: 'Name', title: '產品名稱', width: 150 }, { field: 'Description', title: '描述', width: 250 }, { field: 'Category', title: '品類', width: 150 }, { field: 'Price', title: '價格', width: 150 } ]], toolbar: '#dg-button', singleSelect:true, pagination: true, pageSize: 10, pageList: [10, 20, 30], method: 'get' });})
public ActionResult GetProductList() { var pageSize = Request["rows"] == "" ? 10 : int.Parse(Request["rows"]); var pageNumber = Request["page"] == "" ? 1 : int.Parse(Request["page"]); string Name=string.Empty, order=string.Empty; if(Request["Name"]!=""){ Name=Request["Name"]; } if(Request["order"]!=""){ order=Request["order"]; } IQueryable<Products> products; if (!string.IsNullOrEmpty(Name)) { products = sse.Products.OrderBy(x => x.Name).Where(x=>x.Name.Contains(Name)).Skip((pageNumber - 1) * pageSize).Take(pageSize); } else { products = sse.Products.OrderBy(x => x.ProductID).Skip((pageNumber - 1) * pageSize).Take(pageSize); } var total = sse.Products.Count(); var list = new PageViewModel { rows = products, total = total }; return Json(list,JsonRequestBehavior.AllowGet); }
public class PageViewModel { public int total { get; set; } public IQueryable<Products> rows { get; set; } }