Вопрос

I have a Kendo UI Grid that is displaying the appropriate amount of rows on Read, but there is no data in said rows. Using breaks I check the values of the returned data and the IDs are there. Not sure what's going on. Any help is appreciated. Here is my code

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"))
        )
)

Controller:

public ActionResult EditingPopup_Read([DataSourceRequest] DataSourceRequest request)
    {
        string employeeId = employeeId;

        return Json(globalKip.DisplayExpenseReportLineItems_Employee(employeeId).ToList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);

    }

Model:

    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; }
Это было полезно?

Решение

You have to implement the EditingPopup_Create in the ExpenseReport controller with the following declaration :

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingPopup_Create([DataSourceRequest] DataSourceRequest request,     ExpenseReportModel expenseReportModel, int id)

In which you implement the save of your record into your database

Hope this helps

Другие советы

Try to add this in your Model :

[JsonObject(IsReference = true)]
public class ExpenseReportModel
{
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top