【问题标题】:ASP.NET MVC, where are these parameters coming from?ASP.NET MVC,这些参数从何而来?
【发布时间】:2011-08-31 02:25:00
【问题描述】:

我正在查看 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" });

我的问题是:这些参数是从以下请求生成的?

http://localhost:49290/Home/ProductsGridData/?_search=false&nd=1314749470353&rows=10&page=1&sidx=ProductID&sord=asc

我找不到在代码中的任何位置生成参数“rows”、“page”、“sidx”和“sord”的位置。

【问题讨论】:

  • 我不明白这个问题。你问的是查询字符串吗?
  • @Kirk Woll,请参阅我修改后的问题的底部。如果您还不清楚,请随时询问。

标签: javascript asp.net-mvc


【解决方案1】:

它们是由 jQgrid 本身生成的。您已经告诉它使用寻呼机,因此它将寻呼机查询字符串传递回操作字符串以获取所需的数据。您的应用怎么会知道它只需要从某个页面开始的 10 行?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 2018-07-17
    • 2012-09-22
    • 1970-01-01
    相关资源
    最近更新 更多