我有一个下拉列表,在改变下拉列表时,执行下面的ajax调用,我想从中绑定syncfusion网格。JSON方法正在点击并获取列表,但我无法将数据绑定到网格。
$.post(
"User/GetUserData/",
{ 'CategoryId': CategoryId },
function (data) {
// I want to bind the grid here
});
我尝试了两种方式一种是返回json结果另一种方式返回视图
选项1:
public JsonResult GetUserData(string CategoryId)
{
return Json(model.lstUserModel, JsonRequestBehavior.AllowGet);
}
选项2:
[HttpPost]
public ActionResult GetUserData(string CategoryId)
{
model.lstUserModel= GetUserData(Convert.Int32(CategoryId));
return View("UserView", model);
}
在两个选项中,我无法将数据绑定到列表。
在ajax调用中获得数据后,然后像下面这样将数据绑定到网格。
[HTML]
<div id="Grid"/>
[Script]
$.post(
"User/GetUserData/",
{ 'CategoryId': CategoryId },
function (data) {
$("#Grid").ejGrid({
dataSource: data, // data must be array of json
});
});