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

ListView in RazorPage

1 Answer 228 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 16 Jan 2020, 09:32 AM

Hi, has anyone a running sample of a ListView? Here is my code

the returning json from OnPostReadThumbnails looks good, but the ListView is emtpy

{"data":[{"slfd":"0","sdatname":"Test"}],"total":1,"aggregateResults":null,"errors":null}

 

cshtml.cs

public class IndexModel : PageModel
{
    private readonly ILogger<IndexModel> _logger;
 
    public static IList<ThumbnailViewModel> thumbs;
    public IndexModel(ILogger<IndexModel> logger)
    {
        _logger = logger;
    }
 
    public void OnGet()
    {
        if(thumbs == null)
        {
            thumbs = new List<ThumbnailViewModel>();
            thumbs.Add(new ThumbnailViewModel { SLFD = "0", SDATNAME = "Test" });
        }
    }
 
    public JsonResult OnPostReadThumbnails([DataSourceRequest] DataSourceRequest request)
    {
        return new JsonResult(thumbs.ToDataSourceResult(request));
    }
}

cshtml

<script type="text/x-kendo-tmpl" id="template">
    <div class="product">
        <h3>#:SDATNAME#</h3>
        <h1>#=SLFD#</h1>
        <h2>SDATNAME</h2>
    </div>
</script>
<div class="demo-section k-content wide">
    @(Html.Kendo().ListView<Data.ThumbnailViewModel>()
        .Name("listView")
        .TagName("div")
        .ClientTemplateId("template")
        //.Scrollable(ListViewScrollableMode.Endless)
        .DataSource(ds => ds.Ajax()
            .Read(read => read.Url("/Index?handler=ReadThumbnails").Data("forgeryToken"))
        )
        .Pageable()
    )
</div>

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 21 Jan 2020, 07:53 AM

Hi Marcel,

I have investigated the provided code snippets and I have noticed that there is a mismatch between the field names on the server-side and the ones on the client-side. This is due to the fact that the default serialization of the data in ASP.NET Core is camel case. In order to change the casing, check out the suggestions set in the article below:

https://docs.telerik.com/aspnet-core/getting-started/prerequisites/environment-support#json-serialization

 

Regards,
Tsvetomir
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
ListView
Asked by
Marcel
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Share this question
or