Forum



21:36

05/11/2010

The page number received in my ASP.NET MVC controller action method is always 1 from the jqGrid.
Here is the code in aspx (view) file:
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
<script language="javascript" type="text/javascript">
$(function() {
$("#picJobsBtn").click(function() {
var gridDataUrl = '/CoJobs/JsonJobsCollection';
var loginId = $("#LoginID").val();
jQuery("#list").jqGrid({
url: gridDataUrl + '?loginId=' + loginId + '&jobId=0',
datatype: "json",
mtype: 'GET',
colNames: ['Date', 'Title', 'Job#', 'Location'],
colModel: [
{ name: 'PostDate', index: 'PostDate', width: 50, align: 'left' },
{ name: 'Title', index: 'Title', width: 100, align: 'left' },
{ name: 'PO_Num', index: 'PO_Num', width: 100, align: 'left' },
{ name: 'Location', index: 'Location', width: 100, align: 'left'}],
rowNum: 10,
rowList: [10, 20, 30],
height: 'auto',
width: '700',
page: 1,
pager: '#pager',
sortname: 'PostDate',
viewrecords: true,
sortorder: "desc",
caption: "Pick Job"
}).navGrid("#pager", { edit: false, add: false, del: false });
$("#pickJobTemplate").dialog("open");
return false;
});
})
</script>
Code in the controller:
public ActionResult JsonJobsCollection(int loginId, int jobId, string sidx, string sord, int page, int rows)
{
Job job = new Job();
job.LoginID = loginId;
jobsRepository.GetAll(job, "getAllJobsByLoginId");
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = jobsRepository.ItemsList.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var jobList = jobsRepository.ItemsList.AsQueryable()
.Skip(pageIndex * pageSize)
.Take(pageSize);
var jsonData = new { total = totalPages,
page = page,
records = totalRecords,
rows = (
from s in jobList
select new {
i = s.JobID,
cell = new string[] {
s.PostDate.ToString(),
s.Title.ToString(),
s.PO_Num,
s.Location }
}).ToArray()
};
// Return the result in json
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
When I put a breakpoint in the controller method on the first line (where the new Job object is created) & check the value coming in for page parameter, it is always 1. But in the FireFox browser, using the firebug tool, when I look at the URL that is sent to the server when I click the >> (Next button) after initial grid is loaded, the URL does seem to be sending the value of page as 2. Here is the URL:
Although, the Grid always displays just first 10 records of the Jobs. Also, all subsequent clicks of >> button in pager just sends page=2 in the URL.
Can someone please help me, what am I missing here? Thanks in advance!
19:47

05/11/2010

I figured what the problem was.
In my MVC project, my "catch all" MapRoute entry in global.asax.cs had a default value of page set to 1 & Model Binding by default gets its raw incoming data from RouteDataValueProvider first & then the QueryStringValueProvider.
I removed this route parameter & the Grid works perfect now.
Most Users Ever Online: 715
Currently Online:
51 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66