我正在使用带模板的默认创建按钮。但根据输入,多个记录正在增加。每件事情都很好,直到回归线。我试图返回一个列表作为数据源结果。但它给出了一个错误,如。
Unhandled exception at line 9, column 29037 in http://localhost:63882/Scripts/kendo/2013.3.716/kendo.all.min.js
JavaScript runtime error "0x800a03ec - expected ;"
是否可以将列表作为DataSourceResult返回?
控制器网格创建功能
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult DonemKursSinifiOlustur([DataSourceRequest] DataSourceRequest request, int DonemId, string DersId, string EgitmenId, string Tanim, string dersSuresi, string baslangicSaati, string bitisSaati, string kontenjannsayisi, string TarifeId)
{
List<DonemKursSinifi> models = new List<DonemKursSinifi>();
model.Tanim = Tanim + " " + baslangicSaati + " - ";
baslangicSaati = stringDateAddMinute(baslangicSaati, Convert.ToInt32(dersSuresi));
model.Tanim += baslangicSaati;
model = Helper.Islemci.DonemKursSinifiTanimla(model);
models.Add(model);
while (stringDateKarsilastir(baslangicSaati, bitisSaati) != 1)
{
model.Tanim = Tanim + " " + baslangicSaati + " - ";
baslangicSaati = stringDateAddMinute(baslangicSaati, Convert.ToInt32(dersSuresi));
model.Tanim += baslangicSaati;
model = Helper.Islemci.DonemKursSinifiTanimla(model);
models.Add(model);
}
return Json(new[] { models }.ToDataSourceResult(request, ModelState));//<=error here
}
查看网格
@(Html.Kendo().Grid<Olgu.Kurs.Kurslar.Models.DonemKursSinifi>()
.Name("sinifGrid")
.Columns(columns =>
{
//Columns
columns.Command(command =>
{
command.Edit().UpdateText("Güncelle").CancelText("İptal").Text("Güncelle").HtmlAttributes(new { style = "width:85" });
command.Destroy().Text("Sil").HtmlAttributes(new { style = "width:55;padding 0 0 0 0;", @onclick = "Refresh()" });
}).Width(190);
})
.HtmlAttributes(new { style = "height:410px;width:auto;" })
.Pageable().Scrollable().AutoBind(false)
.Editable(editable => editable.Mode(GridEditMode.PopUp)
.Window(conf => conf.Title("Yeni Sınıf"))
.TemplateName("DonemKursSinifiTemplate")
.DisplayDeleteConfirmation("Seçili kaydı silmek istediğinizden emin misiniz?"))
.ToolBar(toolbar => toolbar.Create().Text("Sınıf Ekle").HtmlAttributes(new { @disabled = "disabled", id = "SinifEkleButton" }))
.Events(e => e.Edit("onEditSinif"))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Sort(s =>
{
s.Add(sinif => sinif.sortString).Ascending();
}
)
.Read(read => read.Action("GridDonemKursSinifi", "Tanim").Data("data"))
.Create(create => create.Action("DonemKursSinifiOlustur", "Tanim").Data("dataCreate"))
.Update(update => update.Action("DonemKursSinifiGuncelle", "Tanim").Data("dataUpdate"))
.Destroy(destroy => destroy.Action("DonemKursSinifiSil", "Tanim"))
.Model(model => model.Id(p => p.Id)))
.Resizable(resize => resize.Columns(true)))
答案 0 :(得分:1)
试试这个
List<DonemKursSinifi> models = new List<DonemKursSinifi>();
model.Tanim = Tanim + " " + baslangicSaati + " - ";
baslangicSaati = stringDateAddMinute(baslangicSaati, Convert.ToInt32(dersSuresi));
model.Tanim += baslangicSaati;
model = Helper.Islemci.DonemKursSinifiTanimla(model);
models.Add(model);
while (stringDateKarsilastir(baslangicSaati, bitisSaati) != 1)
{
model.Tanim = Tanim + " " + baslangicSaati + " - ";
baslangicSaati = stringDateAddMinute(baslangicSaati, Convert.ToInt32(dersSuresi));
model.Tanim += baslangicSaati;
model = Helper.Islemci.DonemKursSinifiTanimla(model);
models.Add(model);
}
DataSourceResult result = new DataSourceResult();
result.Data = models;
result.Total = models.Count;
return this.Json(result);
答案 1 :(得分:1)
你必须像这样转换结果ToDataSourceResult:
IQueryable<DonemKursSinifi> result = (IQueryable<DonemKursSinifi>)model.AsQueryable<DonemKursSinifi>();
DataSourceResult results = result.ToDataSourceResult(request);
results.Total = rows.Count;
results.Data = rows;
return Json(results, "application/json", JsonRequestBehavior.AllowGet);
答案 2 :(得分:0)
试试这个,
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult DonemKursSinifiOlustur([DataSourceRequest] DataSourceRequest dsRequest,DonemKursSinifi model)
{
// Your Code some thing like this.....
List<DonemKursSinifi > list = new List<DonemKursSinifi>();
if (model!= null)
{
list .Add(model);
}
return Json(new DonemKursSinifi [] { model}.ToDataSourceResult(dsRequest, ModelState));
}