Binding complex querystring to a C# model (ASP.NET Core 3.1)

2 posts, 0 answers
  1. Filippo Santoro
    Filippo Santoro avatar
    2 posts
    Member since:
    Dec 2020

    Posted 11 Jan Link to this post

    Dear all,

    I'm using Kendo UI for JQuery and would like to bind the following querystring (generated by default from the grid widget):

    skip=0&page=1&filter[filters][0][value]=Rare Diseases&filter[filters][0][operator]=eq&filter[filters][0][field]=keyword1.keywordValue&filter[logic]=or

    to this model of an ASP.NET Core 3.1 webapp:

     

    public class FSP
    {
        [JsonProperty("take")]
        public int Take { get; set; }
     
        [JsonProperty("skip")]
        public int Skip { get; set; }
     
        [JsonProperty("page")]
        public int Page { get; set; }
     
        [JsonProperty("pageSize")]
        public int PageSize { get; set; }
     
        [JsonProperty("filter")]
        public Dictionary<string,IEnumerable<Dictionary<string, string>>> Filter { get; set; }
    }

     

    All parameters of querystring are correctly mapped, except filter. Furthermore, I would like to avoid changing the querystring using the function transport.parameterMap.

    Could you help me to find the error?

    Thank you in advance.

    Filippo

     

     

  2. Georgi
    Admin
    Georgi avatar
    703 posts

    Posted 13 Jan Link to this post

    Hello Filippo Santoro,

    The easiest option will be to use our DataSourceRequest binder which will bind the query string to a DataSourceRequest model. You can find more about that in the following article:

    Another option would be to create a filter Model and specify to which value each property binds using model binding.

    I hope this helps.

    Regards,
    Georgi
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top