This is a migrated thread and some comments may be shown as answers.

Having an issue displaying data in .NET Core

1 Answer 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 24 Jul 2016, 03:08 AM

So I've got a grid that I believe is all set up correctly. I've confirmed that the data is coming through, and I've even checked that the AJAX call returns a success with the "ToDataSourceResult" JSON data.

 

Unfortunately, the only problem is that the data doesn't display. This seems to only be an issue on read, as update, create and delete all work. Just can't retrieve the list of all items afterwards.

 

My controller action looks like this: 

public IActionResult Blog_Read([DataSourceRequest] DataSourceRequest request)
        {
            var blogs = _blogService.GetPosts().Select(post => new BlogPostModel
            {
                Id = post.Id,
                Title = post.Title,
                Author = post.Author,
                ShortDescription = post.ShortDescription,
                Contents = post.Contents,
                LastSaved = post.LastSaved,
                Published = post.Published,
                PublishedOn = post.PublishedOn
            });
            var result = blogs.ToDataSourceResult(request);
            return Json(result);
        }

 

And my Grid View looks like this:

@(Html.Kendo().Grid<BlogPostModel>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(p => p.Title);
                columns.Bound(p => p.Author).Width(120);
                columns.Bound(p => p.LastSaved).Width(120);
                columns.Bound(p => p.Published).Width(120);
                columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
            })
            .ToolBar(toolbar => toolbar.Create())
            .Editable(editable => editable.Mode(GridEditMode.PopUp))
            .Pageable()
            .Sortable()
            .Scrollable()
            .HtmlAttributes(new { style= "height:600px;"})
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(20)
                .Events(events => events.Error("error_handler"))
                .Model(model => model.Id(p => p.Id))
                .Create(update => update.Action("Blog_Create", "BlogAdmin"))
                .Read(read => read.Action("Blog_Read", "BlogAdmin"))
                .Update(update => update.Action("Blog_Update", "BlogAdmin"))
                .Destroy(update => update.Action("Blog_Delete", "BlogAdmin"))
            )
            .Deferred()
        ) 

 

The correct JSON is returned, no javascript errors in the console, so I'm a little confused as to what this could be. Any help would be greatly appreciated.

 

1 Answer, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 24 Jul 2016, 10:05 PM

I solved this by adding 

 

services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

 

to my Startup.cs ConfigureServices method.

Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Share this question
or