我试图将一些值从jQGrid传递给我的MVC应用程序的控制器。网格显示正常,但没有显示数据。 我的代码在
之下的Ajax
function LoadGrid(varLocationID) {
var jqDataUrl = null;
jqDataUrl = "ManageRoutes/ManageRoutes" //+ x;
var Location = varLocationID.getAttribute('value');
var grid = $("#grid").grid({
url: "/ManageRoutes/GetRoutes/",
postData: { "szLocationID": function () { return Location; } },
cache: false,
datatype: "json",
mtype: "POST",
// Specify the column names
colNames: ["RouteID", "CompanyID", "LocationID", "SalesManCode", "SalesManName"],
// Configure the columns
colModel: [
{ name: "RouteID", index: "RouteID", width: 70, align: "left" },
{ name: "CompanyID", index: "CompanyID", width: 200, align: "left" },
{ name: "LocationID", index: "LocationID", width: 200, align: "left" },
{ name: "SalesManCode", index: "SalesManCode", width: 150, align: "left" },
{ name: "SalesManName", index: "SalesManName", width: 170, align: "left" }
],
pager: { enable: true, limit: 5, sizes: [2, 5, 10, 20] }
});
和控制器中的代码
[HttpPost]
public JsonResult GetRoutes(string szLocationID)
{
List<RouteNames> qry = new List<RouteNames>();
using (TESTEntities1 dc = new TESTEntities1())
{
qry = (from s in dc.t_hhc_dnl_Route_ID.AsEnumerable()
select new RouteNames
{
CompanyID = s.CompanyID,
LocationID = s.LocationID ,
RouteID = s.RouteID,
SalesManCode=s.SalesManCode ,
SalesManName = s.SalesManName
}).Where(m => m.LocationID.Contains(szLocationID)).Take(100).ToList();
}
var jsonData = new
{
data = from emp in qry select emp
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
任何帮助将不胜感激。
答案 0 :(得分:0)
更改为以下代码并开始工作..
"ajax": {
"url": "/ManageRoutes/GetRoutes",
"type": "POST",
"data": function (d) {
d.szLocationID = Location;
}