The date field inside the Kendo Grid is null for the controller

The following code works fine during development, but when deployed to production, the fecha (initly datetime) field gets null.

We even tried to jump to a string instead of datetime, and it still does not work on our client servers.

Our partial view is as follows: fecha.chstml

@using xx.Relacionamiento.Modelo.Bussiness.Entities
@model EventoEducacionFecha
@using Kendo.Mvc.UI

<script type="text/javascript">
    $(function () {
        kendo.culture("es-CO");
    })

    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    }

    function getFecha() {
        debugger
        var fecha = $("#FechaEvent").val();
        return {
            FechaEvent: fecha
        };
    }
</script>
@(Html.Kendo().Grid<EventoEducacionFecha>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.EventoEducacionFechaId).Hidden();
        columns.Bound(p => p.FechaEvent).Title("Fecha Evento").ClientTemplate("#= kendo.toString(kendo.parseDate(FechaEvent, 'yyyy-MM-dd'), 'MM/dd/yyyy') #");
        columns.Bound(p => p.HoraInicio);
        columns.Bound(p => p.HoraFin);
        columns.Command(command =>
        {
            command.Edit().Text("Editar"); 
            //command.Destroy(); 
            command.Custom("Borrar").Click("openWindowConfirmDelete").HtmlAttributes(new { data_NomCol = "FechaEvent" });
        }).Width(250).Title("Acciones");
    })
    .ToolBar(toolbar => toolbar.Create().Text("Agregar Fecha"))
    .Editable(editable => editable.Mode(GridEditMode.InLine).DisplayDeleteConfirmation(false))
    .Pageable()
    .Sortable()
    .Scrollable()
    //.HtmlAttributes(new { style = "height:550px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events => events.Error("error_handler"))
        .Model(model => 
        { 
            model.Id(p => p.EventoEducacionFechaId); 
            model.Field(a => a.EventoEducacionFechaId).Editable(false);
            model.Field(a => a.FechaEvent).Editable(true);
            model.Field(a => a.HoraInicio).Editable(true);
            model.Field(a => a.HoraFin).Editable(true); 
        })
        .Create(update => update.Action("Fechas_Create", "EventosEducacion").Data("getFecha"))
        .Read(read => read.Action("GetFechas", "EventosEducacion").Data("getDatoEventoId"))
        .Update(update => update.Action("Fecha_Update", "EventosEducacion"))
        .Destroy(update => update.Action("Fecha_Destroy", "EventosEducacion"))
    )
)

This is a PART of a view that uses a partial view.

<div class="row oculto" id="VerFecha">
                <div class="col-md-12">
                    <div class="form-group">
                        <div id="mostrarFecha_div"></div>
                        @*@Html.Partial("~/Views/EventosEducacion/Fechas.cshtml",null,null)*@
                    </div>
                </div>

And this is the action of the controller

//[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Fechas_Create([DataSourceRequest] DataSourceRequest request, EventoEducacionFecha EducaFecha, string FechaEvent)
        {
            if (EducaFecha.FechaEvent != null && EducaFecha.HoraInicio != null && EducaFecha.HoraFin != null)
            {
                LstEventoEducacionFecha.Add(new EventoEducacionFecha { 
                EventoEducacionFechaId = Guid.NewGuid(),
                EventoId = Guid.Empty,
                HoraFin = EducaFecha.HoraFin,
                FechaEvent = DateTime.Parse(FechaEvent),
                HoraInicio = EducaFecha.HoraInicio,
                });
                EducaFecha.EventoEducacionFechaId = LstEventoEducacionFecha.OrderBy(o => o.EventoEducacionFechaId).Select(s => s.EventoEducacionFechaId).FirstOrDefault();
                return Json(new[] { EducaFecha }.ToDataSourceResult(request));
            }
            return Json(new[] { EducaFecha }.ToDataSourceResult(request));
        }
+4
source share
3 answers

Kendo , DateTime. DateTime, JavaScript UTC, , c#. , . , - , .

Kendo DateTime Picker js:

 var meetDatePicker = $("#MeetingDate").data("kendoDatePicker");
 var mDate = new Date(meetDatePicker.value());
 var meetDate = mDate.toUTCString();

meetDate c#:

DateTime meetDateConv = DateTime.Parse(meetingDate);
+4

, , . - .

+3

EventoEducacionFecha, FechaEvent. EventoEducacionFecha FechaEvent.

, FechaEvent EventoEducacionFecha.FechaEvent FechaEvent, .

, , /.

FechaEvent getFecha() , .

I assume that the binding order may slightly change between debug and release, but I didn’t see it personally ... whenever I “duplicated” field / parameter names in my controller action, it did not work in both configurations.

+1
source

All Articles