Reputation: 682
I was trying to follow the most recently updated tutorial for jqgrid and MVC3. I have this script:
myGrid.jqGrid({
url: '<%= Url.Action("GridData") %>',
datatype: 'json',
mtype: 'POST',
colNames: ['A', 'B', 'C'],
colModel: [
{ name: 'A', index: 'A', key: true, width: 40
},
{ name: 'B', index: 'B', width: 40
},
{ name: 'C', index: 'C', width: 400
}
],
pager: '#pager',
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'A',
sortorder: 'desc',
rownumbers: true,
viewrecords: true,
altRows: true,
//altclass: 'myAltRowClass',
height: '100%',
gridview: true,
jsonReader: { cell: "" },
caption: 'Grid Title'
});
I have a Controller in the Controllers folder caller HomeController with this inside:
public JsonResult GridData(string sidx, string sord, int page, int rows)
{
return Json(new
{
total = 1, // we'll implement later
page = page,
records = 3, // implement later
rows = (
new[] {
new[]{"A", "B", "C"},
new[]{"1", "2", "3"},
new[]{"X", "Y", "Z"}
}).ToList()
});
}
For some reason I can't get GridData to be called. I set a break point on that function in the controller and it is not being hit.
What could I be missing? Do I need to setup the routing in the project somehow?
Upvotes: 1
Views: 1806
Reputation:
Try changing your Url.Action()
call to this:
<%= Url.Action("GridData", "Home") %>
And just an FYI, this is not Razor syntax. If you are indeed using Razor, it would look like this:
@Url.Action("GridData", "Home")
And last point to ask: where is your JavaScript/jQuery code living? Is it embedded in your View markup?
Upvotes: 1