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

model is null when using kendo grid crud operations

6 Answers 1196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MohamadReza
Top achievements
Rank 1
MohamadReza asked on 07 Mar 2018, 10:48 AM

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 !?


6 Answers, 1 is accepted

Sort by
0
MohamadReza
Top achievements
Rank 1
answered on 08 Mar 2018, 08:31 AM

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 !?

0
MohamadReza
Top achievements
Rank 1
answered on 08 Mar 2018, 06:46 PM

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? :(((

 

 

0
Stefan
Telerik team
answered on 09 Mar 2018, 12:23 PM
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.
0
Development Team
Top achievements
Rank 1
answered on 03 Aug 2020, 04:51 PM
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.
0
Development Team
Top achievements
Rank 1
answered on 03 Aug 2020, 05:01 PM
I figured it out.  ".Batch(true)" should be ".Batch(false)" when posting individual record updates.  Now it works as expected without the Bind Prefix.
0
Petar
Telerik team
answered on 06 Aug 2020, 11:06 AM

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

Tags
Grid
Asked by
MohamadReza
Top achievements
Rank 1
Answers by
MohamadReza
Top achievements
Rank 1
Stefan
Telerik team
Development Team
Top achievements
Rank 1
Petar
Telerik team
Share this question
or