가 여기 내 클라이언트 측 코드의 올바른 JSON 데이터를 반환하는 컨트롤러 액션에도 불구하고, 모든 항목없이 보여주는 :jQuery를 그리드
[RequiresAuthentication]
[HttpPost]
public ActionResult EntryListingByBreed(int showId, int breedId, string sidx, string sord, int page, int rows)
{
using (var dataContext = new NZDogShowsEntities())
{
int pageIndex = page - 1;
int pageSize = rows;
var entries = from se in dataContext.ShowEntries
where se.ShowID == showId && se.Entry.BreedID == breedId
select se;
int totalRecords = entries.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords/(float)pageSize);
var showEntries = (from se in dataContext.ShowEntries.AsEntryListingAggregate().AsEnumerable()
where se.ShowID == showId && se.Entry.BreedID == breedId
select new
{
ID = se.ID,
ClassNumber = se.Class.Number.ToString(),
NZKCRegistration = se.Entry.NZKCRegNumber,
RegisteredName = se.Entry.RegisteredName,
DateOfBirth = se.Entry.DateOfBirth.GetValueOrDefault().ToLongDateString(),
Entered = se.Entry.DateOfBirth.GetValueOrDefault().ToLongDateString()
}).ToList();
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = (
from entry in showEntries
select new
{
i = entry.ID,
cell = new string[]{
entry.ClassNumber,
entry.NZKCRegistration,
entry.RegisteredName,
entry.DateOfBirth,
entry.Entered
}
}).ToArray()
};
var viewData = Json(jsonData);
return viewData;
}
}
}
내 서버 - 여기
$("#grid").jqGrid({
url: "/Entry/EntryListingByBreed/",
datatype: "json",
mtype: "POST",
postData: { showId: showId, breedId: breedId },
colNames: ["Class", "NZKC Reg", "Registered name", "Date of birth", "Entered"],
colModel: [
{ name: "ClassNumber", sortable: false, width: 50 },
{ name: "NZKCRegistration", sortable: false, width: 100 },
{ name: "RegisteredName", sortable: false, width: 200 },
{ name: "DateOfBirth", sortable: false, width: 200 },
{ name: "Entered", sortable: false, width: 200 }
],
pager: jQuery("#pager"),
rowNum: 20,
rowList: [10, 20, 40],
altRows: true,
altclass: "gridAltRow",
viewrecords: true,
caption: "Entries for " + breedName
});
와 나의 서버 측 코드 사이드 코드는 필요 이상으로 길어 보이지만 문제를 해결하는 동안은 좋았습니다. viewData
변수는 모든 올바른 데이터, 행 수, 페이지 번호 등을 표시합니다.
표 형식이 지정됩니다. 모든 크롬 서라운드를 보여줍니다. 그러나 데이터는 표시되지 않습니다. 심지어 "페이지 x/y"가 올바르지 않습니다. 총 레코드 수가 표시되어야하는 "페이지 0 개 중"과 <span>
이 비어 있습니다. 나는 여기서 잃어 버렸어. 아마도 내가 특히이 모든 것에 초보자이기 때문에, 끔찍한 명백한 것을 놓친 것 같다.
어떤 도움말/포인터 (의도적 인)도 크게 감사하겠습니다.
감사합니다.
EDIT : 위의 서버 측 코드는 수정되었으며 이제는 JSON 문자열을 생성합니다. 그것은 올바르게 포맷 된 것으로 보입니다. 위 코드는 업데이트하지 않지만 아래 JSON 문자열을 제공합니다. 그것은 정확하게 파싱하지만 여전히 방화범은 "잘못된 라벨"을보고합니다. 그리드가 채워지지 않습니다! 다음은 문자열입니다 - 내 인생 문제를 발견 할 수없는 경우 :
이{"total":2,"page":1,"records":25,"rows":[{"id":2,"cell":["2a","1234567","Test Dog","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":3,"cell":["4a","abcdef","Test Dog 2","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":4,"cell":["5a","abc123","Test Dog 3","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":5,"cell":["6a","asdf890","Test Dog X","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":6,"cell":["6","qwerty","Test Dog Y","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":7,"cell":["1","fw3asd","Test Dog 4","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":8,"cell":["10","asdfa","Test Dog 5","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":9,"cell":["11a","houh2","Test Dog 6","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":11,"cell":["8","xxxx","Test X","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":12,"cell":["8","zzzz","Test Z","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":13,"cell":["1","qqqq","Test Q","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":14,"cell":["8a","tttt","Test T","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":15,"cell":["8a","rrrr","Test R","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":16,"cell":["7","aaaa","Test A","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":17,"cell":["1","11223344","Test Entry","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":18,"cell":["1","66778899","asdfa","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":19,"cell":["1","13o24bo","qwlen;oq","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":20,"cell":["1","oubiou","asdfa","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":21,"cell":["1","o2no3","hohohop","Monday, 1 January 0001","Monday, 1 January 0001"]},{"id":22,"cell":["1","o48t2","Test 09808","Monday, 1 January 0001","Monday, 1 January 0001"]}]}
jQuery 1.5.1rc1로 테스트하여 문제가 없는지 확인한다. http://blog.jquery.com/2011/02/18/jquery-1-5-1-rc-1-released/이 수정되었습니다. 그렇지 않은 경우 jQuery 버그 추적기 http://bugs.jquery.com/newticket에서보고하십시오. 감사. – rdworth