model is null when using kendo grid crud operations

7 posts, 0 answers
  1. MohamadReza
    MohamadReza avatar
    11 posts
    Member since:
    Jan 2009

    Posted 07 Mar 2018 Link to this post

    hi ..

    i have a dto class called GroupListDto with just three fields

    public class GroupListDto
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
    }

     

    i use this class as kendo grid model ..

    when i write my actionresult in below manner . my model field is empty

    public ActionResult Create([DataSourceRequest] DataSourceRequest request, GroupListDto group)

     

    but when is use GroupListDto class fields instead , the fields are filled with correct datas

    public ActionResult Create([DataSourceRequest] DataSourceRequest request, string Title , string Description)

     

    does anyone know what is the problem ?

    why i cant get data in my dto model , but i get data in its fields !?


  2. MohamadReza
    MohamadReza avatar
    11 posts
    Member since:
    Jan 2009

    Posted 08 Mar 2018 Link to this post

    also when i enable batch edit in kendo grid

    .Batch(true)

     

    and change the GroupListDto to IEnumerable<GroupListDto> , everything gets correct and i get the list of the data

    public ActionResult Create([DataSourceRequest] DataSourceRequest request,
                                          [Bind(Prefix = "models")]IEnumerable<GroupListDto> groups)

    but as i mentioned before , i dont need batch edit , i just want to get one row of GroupListDto in my controller..

    does anyone know what is wrong with my code !?

  3. MohamadReza
    MohamadReza avatar
    11 posts
    Member since:
    Jan 2009

    Posted 08 Mar 2018 Link to this post

    after spending a lot of time on this issue i found this way .

    public ActionResult CreateLite([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models[0]")]GroupListDto group)

     

    by adding models[0] , i was able to get the edited recored data ..

    but i think [Bind(Prefix = "models[0]")  is something extra and must be removed from my actionresult ..

    who knows the answer of my problem? :(((

     

     

  4. Stefan
    Admin
    Stefan avatar
    3034 posts

    Posted 09 Mar 2018 Link to this post

    Hello, Mohamad,

    Thank you for providing all of the details when researching the issue.

    The only thing that I noticed is that the following decorator is missing:

    [AcceptVerbs(HttpVerbs.Post)]

    Please observe all of the code in our Inline edit demo without Batch enabled:

    https://demos.telerik.com/aspnet-core/grid/editing-inline

    Also, observe if the requests in the network tab are in different format.

    Additionally, providing a runnable example will help us test it locally and make a suggestion best suited for it.

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Development Team
    Development Team avatar
    2 posts
    Member since:
    Apr 2018

    Posted 03 Aug 2020 in reply to MohamadReza Link to this post

    Did you ever find a root cause / solution for this?  I too had to add '[Bind(Prefix = "models[0]")' in order to get it working properly.  Everything else in my case matched up to the inline editing demo for ASP.NET Core.  Without that, though the HTTP request had all of the data in the post, the model on the server side would be seen as a new instance where all fields were null.
  6. Development Team
    Development Team avatar
    2 posts
    Member since:
    Apr 2018

    Posted 03 Aug 2020 in reply to Development Team Link to this post

    I figured it out.  ".Batch(true)" should be ".Batch(false)" when posting individual record updates.  Now it works as expected without the Bind Prefix.
  7. Petar
    Admin
    Petar avatar
    458 posts

    Posted 06 Aug 2020 Link to this post

    Hi,

    Thank you for sharing what has resolved the issue in the application you are working on! Your response will surely help someone who experience the same issue in the future. 

    Regards,
    Petar
    Progress Telerik

Back to Top