简体   繁体   中英

Using kendoGrid in mvc5

I want to show some information in a kendoGrid() (editing-popup) but when I run the project it does not load the data and the grid is empty.

What should I do???

 @(Html.Kendo().Grid<TelerikTestProject.Models.SoftwareInformation>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.SoftwareID);
        columns.Bound(p => p.Name).Width(100);

        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
    })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:430px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events => events.Error("error_handler"))
        .Model(model => model.Id(s =>s.SoftwareID ))
                .Create(update => update.Action("Create", "SoftwareInformations"))
        **.Read(read => read.Action("Index", "the name of my controller"))**
        .Update(update => update.Action("EditingPopup_Update", "Grid"))
        .Destroy(update => update.Action("EditingPopup_Destroy", "Grid"))
    )
)
<script type="text/javascript">
    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    }
</script>

I have done it my application this way-

@using Kendo.Mvc.UI
@model IEnumerable<DFMS_MVC5.Models.DIM_LINKS>


    @(Html.Kendo().Grid<DFMS_MVC5.Models.DIM_LINKS>(Model)
    .Name("grid")
    .Columns(columns => {
        columns.Bound(p => p.ID_DIM_LINK);
        columns.Bound(p => p.LINK_NAME);
        columns.Bound(p => p.LINK_DESC);
        columns.Bound(p => p.CREATE_TIME_STAMP).Format("{0:MM/dd/yyyy}");
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .HtmlAttributes(new { style = "height:550px;" })
     )

See if this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM