Datetime column

Hi,
I have an issue when update a record eith dialog template, client return this alert: The value 'Thu Mar 27 2014 19:23:58 GMT+0100 (ora solare Europa occidentale)' is not valid for Data.

In my model the field DataNews is a DateTime.

This is grid row:
col.Field("DataNews").Format("{0:dd/MMM/yyyy}").Add();

This is field in template:
<input  name="DataNews" value="{{: DataNews}}" />

This is the value that return when edit record:
Thu Mar 27 2014 19:23:58 GMT+0100 (ora solare Europa occidentale)




5 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team January 10, 2018 03:31 PM UTC

Hi Pio, 

Thanks for contacting Syncfusion Support. 

We have checked your query and while using DateColumn in the Grid, when we edit or update the record, it displays the date value in the form of datetimeobj ex: ( Thu Mar 27 2014 19:23:58 GMT+0100. When you are using format property, it displays the date column in the mentioned format on Grid.  
  
So, we need some additional information to find the cause the issue.  Please share us the following details. 

1. Complete Grid code example(both in server and client side). 

2. Exact scenario you are facing the issue(while editing or saving the record). 

3. Screenshot/Video Demo to replicate the issue. 

4. If possible provide a simple issue reproducing sample. 

The provided information will be helpful to provide you response as early as possible. 

Regards, 

Farveen sulthana T 



PL Pio Luca Valvona January 10, 2018 03:58 PM UTC

Hi Farveen,
I have the issue only when update a record, because when I insert new recod set Data to DateTime.Now.
This is the code:

Model:
public class NewsVM
    {
        [Key]
        public Guid IDNews { getset; }
 
        [Display(Name = "DataNews", ResourceType = typeof(Resources.News))]
        public DateTime DataNews { getset; }
 
        [Display(Name = "TitoloNews", ResourceType = typeof(Resources.News))]
        public string Titolo { getset; }
 
        [Display(Name = "TitoloNewsIng", ResourceType = typeof(Resources.News))]
        public string Titolo_Ing { getset; }
 
        [Display(Name = "DescrizioneNews", ResourceType = typeof(Resources.News))]
        public string Descrizione { getset; }
 
        [Display(Name = "DescrizioneNewsIng", ResourceType = typeof(Resources.News))]
        public string Descrizione_Ing { getset; }
 
        [Display(Name = "Link", ResourceType = typeof(Resources.News))]
        public string LinkNews { getset; }
 
        [Display(Name = "Click", ResourceType = typeof(Resources.News))]
        public int Click { getset; }
    }
Controller:
[Authorize(Roles = ("Administrator"))]
        [HttpPost]
        [ValidateInput(false)]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> CrudNewsUrl(NewsVM value, Guid? key, string action)
        {
 
            log4net.Config.XmlConfigurator.Configure();
            log.Info("Inizio esecuzione CrudUrl(NewsVM value, Guid? key, string action)");
            try
            {
                if (string.IsNullOrEmpty(value.Titolo))
                {
                    ModelState.AddModelError(Resources.News.TitoloNews, Resources.News.TitoloObbligatorio);
                }
                if (string.IsNullOrEmpty(value.Titolo_Ing))
                {
                    ModelState.AddModelError(Resources.News.TitoloNewsIng, Resources.News.TitoloIngObbligatorio);
                }
                if (string.IsNullOrEmpty(value.Descrizione))
                {
                    ModelState.AddModelError(Resources.News.DescrizioneNews, Resources.News.DescrizioneObbligatorio);
                }
                if (string.IsNullOrEmpty(value.Descrizione_Ing))
                {
                    ModelState.AddModelError(Resources.News.DescrizioneNewsIng, Resources.News.DescrizioneIngObbligatorio);
                }
 
                if (action == "update")
                {
 
                    if (ModelState.IsValid)
                    {
                        News news = new News()
                        {
                            Click = value.Click,
                            DataNews = value.DataNews,
                            Descrizione = Server.HtmlEncode(value.Descrizione),
                            Descrizione_Ing = Server.HtmlEncode(value.Descrizione_Ing),
                            IDNews = value.IDNews,
                            LinkNews = value.LinkNews,
                            Titolo = value.Titolo,
                            Titolo_Ing = value.Titolo_Ing
                        };
 
                        if (await _newsRepository.UpdNews(news) != 1)
                        {
                            HttpContext.Response.AddHeader("Exception", Server.HtmlEncode(Resources.Common.ErroreTrasmissione));
                            Response.StatusCode = 412;
                        }
                    }
                    else
                    {
                        var message = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
                        HttpContext.Response.AddHeader("Exception", Server.HtmlEncode(message));
                        Response.StatusCode = 412;
                    }
                }
                else if (action == "insert")
                {
                    ModelState.Remove("value.IDNews");
                    ModelState.Remove("value.DataNews");
                    value.IDNews = Guid.NewGuid();
                    value.DataNews = DateTime.Now;
 
                    if (ModelState.IsValid)
                    {
                        News news = new News()
                        {
                            Click = value.Click,
                            DataNews = value.DataNews,
                            Descrizione = Server.HtmlEncode(value.Descrizione),
                            Descrizione_Ing = Server.HtmlEncode(value.Descrizione_Ing),
                            IDNews = value.IDNews,
                            LinkNews = value.LinkNews,
                            Titolo = value.Titolo,
                            Titolo_Ing = value.Titolo_Ing
                        };
 
                        if (await _newsRepository.InsNews(news) != 1)
                        {
                            HttpContext.Response.AddHeader("Exception", Server.HtmlEncode(Resources.Common.ErroreTrasmissione));
                            Response.StatusCode = 412;
                        }
                    }
                    else
                    {
                        var message = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
                        HttpContext.Response.AddHeader("Exception", Server.HtmlEncode(message));
                        Response.StatusCode = 412;
                    }
                }
                else if (action == "remove")
                {
                    if (key == nullreturn new
                      HttpStatusCodeResult(HttpStatusCode.BadRequest);
 
                    await _newsRepository.DelNews(key);
                }
                log.Info("Fine esecuzione CrudUrl(NewsVM value, Guid? key, string action)");
            }
            catch (Exception ex)
            {
 
                log.Error(string.Format("Errore:{0}", ex.InnerException == null ? ex.Message : ex.InnerException.Message));
                var message = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                HttpContext.Response.AddHeader("Exception", Server.HtmlEncode(message));
                Response.StatusCode = 412;
            }
            return Json(value, JsonRequestBehavior.AllowGet);
        }
View:

see attachment.

Regards


Attachment: view_f4ea4bbf.zip


RS Renjith Singh Rajendran Syncfusion Team January 11, 2018 05:33 PM UTC

Hi Pio, 
  
We have analyzed your code examples. We could see that you are using the template for the datetime column an input element. So we suggest you to set the EditType property of the datetime column as DateTimePicker and in the ActionComplete event of Grid render the ejDateTimePicker control for the input element. This will allow you to select proper datetime value to be updated in Grid. Please refer the code example below, 
  
    @(Html.EJ().Grid<NewsVM> 
        ("NewsGrid").Datasource(ds => ds.Json(Model).CrudURL(Url.Action("CrudNewsUrl", "Admin")).Adaptor(AdaptorType.RemoteSaveAdaptor)).AllowTextWrap().TextWrapSettings(wrap => { wrap.WrapMode(WrapMode.Both); }) 
        .Columns(col => 
        {            ... 
           col.Field("DataNews").Format("{0:" + datePattern + "}").EditType(EditingType.DateTimePicker).Add(); 
            ... 
        }) 
        .ClientSideEvents(eve => eve.ActionComplete("complete") ) 
        ) 
  
  
<script type="text/javascript"> 
    function complete(args) { 
           if (args.requestType == "beginedit" || args.requestType == "add") { 
                    ... 
                   $("#DataNews").ejDateTimePicker(); 
                    ... 
                } 
            } 
    } 
</script> 
  
  
<script type="text/template" id="NewsTemplate"> 
    @Html.AntiForgeryToken() 
    ... 
    <input id="DataNews" name="DataNews" value="{{: DataNews}}" /> 
    ... 
</script> 
  
  
Please refer the documentation link below, 
  
Please get back to us if you need further assistance. 
  
Regards, 
Renjith Singh Rajendran. 



PL Pio Luca Valvona January 12, 2018 09:14 AM UTC

Hi Renjith,
thank you, it works well now.

Regards

Luca


RS Renjith Singh Rajendran Syncfusion Team January 16, 2018 03:59 AM UTC

Hi Luca, 

Thanks for the update.  

We are happy to hear that your requirement has been achieved. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


Loader.
Up arrow icon