在asp.net MVC页面中,我有这个网格
<div>
@(Html.Kendo().Grid<KerberosTest.Models.Bench>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.id);
columns.Bound(p => p.name);
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
//.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
//.ServerOperation(true)
.Read(read => read.Action("GetBenches", "home"))
)
)
</div>
我的数据来自我HomeController.cs中的这个方法
public async Task<ActionResult> GetBenches()
{
BenchesService bService = new BenchesService();
List<Bench> obj = await bService.getBenches();
Console.WriteLine("ALAL");
var action = Json(obj.Select(s => new Bench
{
id = s.id,
bookable = s.bookable,
name = s.name,
seatsCount = s.seatsCount,
zone = s.zone
}).Distinct(), JsonRequestBehavior.AllowGet);
return action;
}
调用另一个
public async Task<List<Bench>> getBenches()
{
List<Bench> jsonOBJ = new List<Bench>();
try
{
using (var client = new HttpClient())
{
client.BaseAddress = Constants.baseAddress;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + Constants.token);
client.DefaultRequestHeaders.Add("apiKey", Constants.apiKey);
// New code:
HttpResponseMessage response = await client.GetAsync("bench/list");
if (response.IsSuccessStatusCode)
{
Stream sResposta = await response.Content.ReadAsStreamAsync();
string res = new StreamToStringcs().ConvertStream(sResposta);
jsonOBJ = JsonConvert.DeserializeObject<List<Bench>>(res, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return jsonOBJ;
}
最后这是我的替补课
public class Bench
{
public int id { get; set; }
public string name { get; set; }
public bool bookable { get; set; }
public int zone { get; set; }
public int seatsCount { get; set; }
//public type bookedSeats {get;set;}
}
我的问题是我的网格显示任何行。它会在一段时间内显示加载条,然后它会保持强制状态。 使用断点我可以看到List obj变量被350 Bench填充。
我错过了什么?
答案 0 :(得分:1)
尝试将ToDataSourceResult()扩展名添加到GetBenches结果
public async Task<ActionResult> GetBenches([DataSourceRequest] DataSourceRequest request)
{
BenchesService bService = new BenchesService();
List<Bench> obj = await bService.getBenches();
Console.WriteLine("ALAL");
return Json(obj.Select(s => new Bench
{
id = s.id,
bookable = s.bookable,
name = s.name,
seatsCount = s.seatsCount,
zone = s.zone
}).Distinct().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
这将创建一个带有Data属性的json对象,该属性包含您的数据。我相信MVC辅助网格会查找此Data属性。
如果您还没有using Kendo.Mvc.Extensions;
,可能需要将[DataSourceRequest] DataSourceRequest request
添加到控制器中。
BTW (lldb) po self.faqTextView.attributedText
Test 1:{
NSFont = "<UICTFont: 0x7f91b94bdee0> font-family: \".HelveticaNeueInterface-Regular\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
}
具有进行分页和排序所需的参数,因此如果要使用服务器端分页和过滤,则必须将其作为参数包含在ActionResult中。不确定如果你在客户端上这样做是否重要