ASP.net MVC 3 で jqGrid をレンダリングする際に問題があります。ProductInfo アクションの責任は、製品のリストを他の最新の製品情報 ( ProductInfo ビュー) と共に表示することです。ユーザーが製品リンクをクリックすると、ProductModelList アクションは選択した製品のすべてのモデルリストを取得し、すべての jqGrid コードが書き込まれるProductModelList ビューに渡します。ただし、次のようにブラウザーで行のjsonデータをレンダリングします
{"total":null,"page":null,"records":9,"rows":[{"id":4,"cell":["3","Hyundai Accent"]},{"id ":5,"cell":["3","現代サントロ"]},{"id":6,"cell":["3","現代サンタフェ"]},{"id":7 ,"セル":["3","ヒュンダイ i10"]},{"id":8,"セル":["3","ヒュンダイ i20"]},{"id":9,"セル" :["3","ヒュンダイ ツーソン"]},{"id":10,"セル":["3","ヒュンダイ ヴェルナ フルイディック"]},{"id":11,"セル":[" 3","Hyundai EON"]},{"id":12,"cell":["3","New Hyundai Sonata"]}]}
以下はコントローラーとビューです。
public class Product : Controller
{
**//used to view product list**
public ActionResult ProductInfo()
{
ViewBag.ModelNameList = ModelRepository.GetModelName();
ViewBag.ModelVersionNameList = ModelVersionRepository.GetModelVersionName();
return View(new NewCarSearchContainer());
}
**//used to view modellist using jgGrid**
public JsonResult ProductModelList(int brandId, string sidx, string sord, int? page, int? rows)
{
var result = new
{
total = (ModelRepository.GetModelByBrandId(brandId).Count() + rows - 1) / rows,
page = page,
records = ModelRepository.GetModelByBrandId(brandId).Count(),
rows = (from model in ModelRepository.GetModelByBrandId(brandId)
select new
{
id = model.ModelId,
cell = new string[] { model.BrandId.ToString(), model.ModelName }
}).ToList()
};
return Json(result, JsonRequestBehavior.AllowGet);
}
}
ProductModelList View:
=====================
<table id="jqgProducts">
</table>
<div id="jqgpProducts">
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#jqgProducts').jqGrid({
//url from wich data should be requested
url: '/Product/ProductModelList',
//type of data
datatype: 'json',
//url access method type
mtype: 'GET',
//columns names
colNames: ['id', 'ModelId', 'BrandName'],
//columns model
colModel: [
{ name: 'id', index: 'id', width: 40, align: 'left' },
{ name: 'ModelId', index: 'ModelId', width: 40, align: 'left' },
{ name: 'BrandName', index: 'BrandName', width: 40, align: 'left' },
],
//pager for grid
pager: $('#jqgpProducts'),
//number of rows per page
rowNum: 10,
//initial sorting column
sortname: 'ModelId',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
//grid height
height: '100%'
});
});
</script>
私を案内してください?
ありがとう、
ポール