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

Insertonsubmit not saving to DB

4 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ams
Top achievements
Rank 1
ams asked on 21 May 2018, 07:01 AM

I have a Html.Kendo().Grid in my aspx page.DataSource is defined like below

.DataSource(ds => ds
.Ajax()
.Model(model =>
{
model.Id(m => m.ID);
model.Field(m => m.ID).Editable(false);
})
.Read(r => r.Action("GetValues", "Home"))
.Update(update => update.Action("UpdateValues", "Home"))
.Create(update => update.Action("UpdateValues", "Home", new { optionType="value" }))
)

 

Controller Method

 

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateValues([DataSourceRequest] DataSourceRequest dsRequest, Value val, string optionType)
{
try
{
if (val!= null && ModelState.IsValid)
{
long _id;
_id = Convert.ToInt64(val.ID);
if (val.ID== 0)
{
val.ModifiedBy = val.ModifiedBy == null ? base.User: val.ModifiedBy;
                        val.ModifiedDate = DateTime.Now;
}
else
{
val= repository.Value[_id];
}


if (val!= null && ModelState.IsValid)
{
if (val.ID != 0)
{

                            TryUpdateModel(val);
                            repository.Value.Save(val);
}
else
{


                            repository.Value.Save(val);
}

}
}
}
catch(Exception ex)
{

}
return Json(ModelState.ToDataSourceResult(),JsonRequestBehavior.AllowGet);
}

 

 

The ModifiedDate column in DB table has default value as Getdate()

 

Upon trying to add a new value to the grid,I am getting below response from json.

{"Errors":"ModifiedDate":{"errors":["the value "\u00275/21//2018 4:23:16 AM\u0027"  is not valid for ModifiedDate"}}}

 

 

Can someone help.What am I doing wrong here

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 22 May 2018, 06:57 AM
Hello, Ams,

Thank you for the details.

After inspecting the example I noticed that the ModelState is returned instead of the actual record.

I can suggest inspecting our editing examples and the "Editing_InlineController.cs":

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

All demos are available in the runnable solution as well, so you can test them and debug certain part of the code:

https://docs.telerik.com/kendo-ui-mvc/introduction#sample-application

Also, the Ajax editing article could prove useful as well:

https://docs.telerik.com/aspnet-mvc/helpers/grid/editing/ajax-editing

I hope this is helpful.

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
ams
Top achievements
Rank 1
answered on 25 May 2018, 12:03 PM

Tried changing the value returned from the controller method as mentioned in the demos.In local code,this works fine.But while deploying to server,the same error happens and value is not saved to DB.

 

Will this be anyway related to DB collation?

0
Stefan
Telerik team
answered on 28 May 2018, 05:34 AM
Hello, Ams,

If the application is working locally and not working after deployment, could you please check if any of the files are cached. Please inspect the loaded scripts after deployment and check if they are indeed the new files after the change.

If they are, please check the value of the ModifiedDate to ensure that is indeed a valid date.

If the issue still occurs, providing a live URL could allow us to debug it and provide a solution if possible.

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
ams
Top achievements
Rank 1
answered on 31 Jul 2018, 11:10 AM
Issue was with date property  of  modelstate.ModelsTate.IsValid was setting to false due to the system date format
Tags
Grid
Asked by
ams
Top achievements
Rank 1
Answers by
Stefan
Telerik team
ams
Top achievements
Rank 1
Share this question
or