我正在查看ASP.NET MVC项目的jqGrid实现示例。但我无法弄清楚这段代码中的参数来自哪里?
/// <summary>
/// Editing product
/// </summary>
/// <param name="postData">postData collection</param>
/// <returns>json data</returns>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditProduct(FormCollection postData)
{
//Editing product based on postData
Product product = _repository.GetProduct(Convert.ToInt32(postData["id"]));
product.ProductName = postData["ProductName"];
product.SupplierID = Convert.ToInt32(postData["Supplier"]);
product.CategoryID = Convert.ToInt32(postData["Category"]);
product.QuantityPerUnit = postData["QuantityPerUnit"];
product.UnitPrice = Convert.ToDecimal(postData["UnitPrice"].Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
product.UnitsInStock = Convert.ToInt16(postData["UnitsInStock"]);
//Sending changes back to repository
bool success = true;
try
{
_repository.SubmitChanges();
}
catch (Exception ex)
{
Debug.Write(ex.Message);
success = false;
}
//Returning data - we can hadle this data in form afterSubmit event
return Json(success);
}
这是相关的HTML代码;
<script type="text/javascript">
$(document).ready(function() {
$('#jqgProducts').jqGrid({
//url from wich data should be requested
url: '/Home/ProductsGridData/',
//type of data
datatype: 'json',
//url access method type
mtype: 'GET',
//columns names
colNames: ['ProductID', 'ProductName', 'SupplierID', 'CategoryID', 'QuantityPerUnit', 'UnitPrice', 'UnitsInStock'],
//columns model
colModel: [
{ name: 'ProductID', index: 'ProductID', align: 'left' },
{ name: 'ProductName', index: 'ProductName', align: 'left' },
{ name: 'SupplierID', index: 'SupplierID', align: 'left' },
{ name: 'CategoryID', index: 'CategoryID', align: 'left' },
{ name: 'QuantityPerUnit', index: 'QuantityPerUnit', align: 'left' },
{ name: 'UnitPrice', index: 'UnitPrice', align: 'left' },
{ name: 'UnitsInStock', index: 'UnitsInStock', align: 'left' }
],
//pager for grid
pager: $('#jqgpProducts'),
//number of rows per page
rowNum: 10,
//initial sorting column
sortname: 'ProductID',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
//grid width
width: 'auto',
//grid height
height: 'auto'
});
});
</script>
</asp:Content>
<asp:Content ID="cContent" ContentPlaceHolderID="cphContent" runat="server">
<table id="jqgProducts" cellpadding="0" cellspacing="0"></table>
<div id="jqgpProducts" style="text-align:center;"></div>
</asp:Content>
默认路线为:
routes.MapRoute("Default", "{controller}/{action}", new { controller = "Home", action = "Basics" });
我的问题是:以下请求产生的这些参数在哪里?
我找不到参数“rows”,“page”,“sidx”和“sord”在代码中的任何位置生成的位置。
答案 0 :(得分:1)
它们是由jQgrid本身生成的。您已经告诉它使用寻呼机,因此它将寻呼机查询字符串传递回actionstring以获取所需的数据。你的应用怎么会知道它只想从某个页面开始10行?