Insertonsubmit not saving to DB

5 posts, 0 answers
  1. ams
    ams avatar
    4 posts
    Member since:
    Aug 2017

    Posted 21 May 2018 Link to this post

    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

  2. Stefan
    Admin
    Stefan avatar
    3008 posts

    Posted 22 May 2018 Link to this post

    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.
  3. ams
    ams avatar
    4 posts
    Member since:
    Aug 2017

    Posted 25 May 2018 Link to this post

    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?

  4. Stefan
    Admin
    Stefan avatar
    3008 posts

    Posted 28 May 2018 Link to this post

    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.
  5. ams
    ams avatar
    4 posts
    Member since:
    Aug 2017

    Posted 31 Jul 2018 Link to this post

    Issue was with date property  of  modelstate.ModelsTate.IsValid was setting to false due to the system date format
Back to Top