我想知道如何通过将Id传递给控制器的post方法来生成jqgrid? jqgrid中是否有任何postdata类型的属性?请给我详细的例子来生成基于特定id的jqgrid以及如何在控制器的post方法中获取这个Id?
让我再说一遍......
这里我的控制器方法返回View:
public ActionResult Index1(int Id)
{
ViewBag.Id = Id;
return View("Index");
}
现在这个索引视图在这里:
$(document).ready(function () {
$("#AssetTable").jqGrid({
url: '/Controller/List',
mtype: 'POST',
datatype: "json",
jsonReader: {
root: "rows", //array containing actual data
page: "page", //current page
total: "total", //total pages for the queryd
records: "records", //total number of records
repeatitems: false,
id: "ID" //index of the column with the PK in it
},
colNames: ['ID', 'Dedicated', 'Post Of'],
colModel: [
{ name: 'ID', width: 150, formatter: myLinkFormatter },
{ name: 'Dedicated', width: 300},
{ name: 'PostOf', width: 300 }
],
rowNum: 10,
rowList: [10, 15, 20],
pager: '#AssetTablePager',
sortname: 'Dedicated',
viewrecords: true,
sortorder: "asc",
caption: "Armories",
height: "auto",
width: "auto",
altRows: true,
altclass: 'OddGridRow'
});
这是我的控制器的post方法,它生成jqgrid 这里我希望Id作为参数,因为我想基于此id生成网格:
public override JsonResult List(int? page, int? rows, string sidx, string sord, bool _search, string searchField, string searchOper, string searchString)
{
var _db = new AOAEntities();
// Create the Repository and get the Model
List<vendor> _data = new VendorRepository().GetList();
//load the Model in to the ViewModel
List<VendorVM> _vendors = _data.Select(x => new VendorVM
{
ID = x.id_vendor,
Name = x.nm_vendor.Trim(),
DefaultObjectCode = x.object_codes == null ? "" : x.object_codes.ds_code.Trim() + "-" + x.object_codes.ds_description.Trim(),
AddressLine1 = x.ds_address_line1.Trim(),
City = x.ds_city.Trim(),
Phone = x.ds_phone.Trim()
}).ToList();
int _page = page ?? 1;
int _rows = rows ?? 1;
if (_search)
{
_vendors = _vendors.AsQueryable().Where(searchField, searchString, searchOper).ToList();
}
var sortedAssets = _vendors.AsQueryable().SortBy(string.Format("{0} {1}", sidx, sord));
sortedAssets = sortedAssets.Skip((_page - 1) * _rows).Take(_rows);
var pagedAssets = (_vendors.Count / rows) + (_vendors.Count % rows == 0 ? 0 : 1);
var results = new
{
total = pagedAssets, //number of pages
page = page, //current page
records = _vendors.Count(), //total items
rows = sortedAssets
};
return Json(results);
}
我的问题是如何在此方法中获取id(公共覆盖JsonResult List)
答案 0 :(得分:0)
您可以使用Url.Action helper包含id参数。观点:
...
url: $("#GetQueueGridAction").data("url"),
...
<div id="GetQueueGridAction" data-url="@Url.Action("GetAction", "Controller", new { id = ViewBag.Id })"></div>
然后在控制器方法签名中:
public JsonResult GetQueue(int id, string sidx, string sord, int page, int rows)