Having an issue displaying data in .NET Core

2 posts, 0 answers
  1. Adam
    Adam avatar
    9 posts
    Member since:
    Jun 2016

    Posted 23 Jul 2016 Link to this post

    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:

                .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))
                .HtmlAttributes(new { style= "height:600px;"})
                .DataSource(dataSource => dataSource
                    .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"))


    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.


  2. Adam
    Adam avatar
    9 posts
    Member since:
    Jun 2016

    Posted 24 Jul 2016 in reply to Adam Link to this post

    I solved this by adding 


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


    to my Startup.cs ConfigureServices method.

Back to Top