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

ModelState Invalid on Create

2 Answers 796 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 09 Mar 2018, 01:19 PM

I'm using a Grid, with InLine AJAX editing enabled. The grid has a single text column, and my Model has an ID property (a GUID).  When I add a row to the grid, set the text value, and hit Save, on the server the ModelState.IsValid property is set to false and it's complaining about the empty ID.  Of course it's empty - the database assigns that.

How do I get that to stop being treated as invalid? I already have the ID decorated as DatabaseGenerated (I'm using efcore). Help!

2 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 09 Mar 2018, 02:19 PM
I should also note, my DataSource is set up with a call to Model(m => m.Id(p => p.Id)) so it should know that the Id field is my primary key.     
1
Konstantin Dikov
Telerik team
answered on 12 Mar 2018, 09:48 AM
Hello Robert,

When an INT type is used for the ID, when a new record is created it will receive 0 as default value. However, with GUID you will have to explicitly set default value in the DataSource configuration as discussed in the following forum thread:
Hope this helps.


Regards,
Konstantin Dikov
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.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or