我有一个Kendo UI Grid,它在Read上显示适当的行数,但所述行中没有数据。使用中断我检查返回数据的值,ID就在那里。不知道发生了什么事。任何帮助表示赞赏。这是我的代码
CSHTML:
@(Html.Kendo().Grid<ExpenseReport.MVC.Models.ExpenseReportModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ExpenseReportId);
columns.Bound(p => p.ExpenseTypeDesc).Title("Expense Type");
columns.Bound(p => p.City).Title("City");
columns.Bound(p => p.StateName).Title("State");
columns.Bound(p => p.Date).Format("{0:d}").Title("Date");
columns.Bound(p => p.Amount).Title("Amount");
columns.Bound(p => p.EndingMileage).Title("Ending Mileage");
columns.Bound(p => p.BeginningMileage).Title("Beginning Mileage");
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(toolbar => toolbar.Create().HtmlAttributes(new { id = "btnAdd" }))
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("NewExpense").Window(w => w.Width(500)))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:430px; width=100%" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.ExpenseReportId))
.Create(create => create.Action("EditingPopup_Create", "ExpenseReport"))
.Read(read => read.Action("EditingPopup_Read", "ExpenseReport"))
.Update(update => update.Action("EditingPopup_Update", "ExpenseReport"))
.Destroy(destroy => destroy.Action("EditingPopup_Destroy", "ExpenseReport"))
)
)
控制器:
public ActionResult EditingPopup_Read([DataSourceRequest] DataSourceRequest request)
{
string employeeId = employeeId;
return Json(globalKip.DisplayExpenseReportLineItems_Employee(employeeId).ToList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
型号:
public int ExpenseLineItemId { get; set; }
public SelectList ExpenseTypeList { get; set; }
public string ExpenseTypeID { get; set; }
[Display(Name="Expense Type")]
public string ExpenseTypeDesc { get; set; }
public string City { get; set; }
public SelectList StateList { get; set; }
[Display(Name = "State")]
public string StateName { get; set; }
public string StateID { get; set; }
public DateTime? Date { get; set; }
public decimal? Amount { get; set; }
[Display(Name="Ending Mileage")]
public int? EndingMileage { get; set; }
[Display(Name="Beginning Mileage")]
public int? BeginningMileage { get; set; }
答案 0 :(得分:0)
您必须使用以下声明在ExpenseReport控制器中实现EditingPopup_Create:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingPopup_Create([DataSourceRequest] DataSourceRequest request, ExpenseReportModel expenseReportModel, int id)
在其中实现将记录保存到数据库中
希望这有帮助
答案 1 :(得分:0)
尝试将其添加到您的模型中:
[JsonObject(IsReference = true)]
public class ExpenseReportModel
{