post dates from asp.net mvc to controller

4 posts, 0 answers
  1. sanjay
    sanjay avatar
    3 posts
    Member since:
    Nov 2014

    Posted 20 Sep 2015 Link to this post

    I've following grid with inline edit. For selecting date and time they have their respective date and time controls. I want to post date in '12-Sep-2015 12.00.00' format and time in '09:00:00' format to mvc control action. But when I post the data, date is in the 'Wed Sep 23 2015 00:00:00 GMT-0400 (Eastern Daylight Time)' format. Time is in the 'Sat Sep 19 2015 15:00:00 GMT-0400 (Eastern Daylight Time)' format. This only happens if I change date and time value. If I don't change, values are posted the way I want to. What do I do to post data in proper format after edit?

     

    @(Html.Kendo().Grid<Kyklos.ClinicPortal.ViewModels.AppointmentViewModel>()
                .Name("UpCmgApptGrid").
                Columns(columns =>
                {                
                    columns.Bound(c => c.strAppintmentDate).Title("Appintment Date").Format("{0:MM/dd/yyyy}").EditorTemplateName("Date");
                    columns.Bound(c => c.strAppintmentTime).Title("Appintment Time").Format("{0:hh:mm tt}").EditorTemplateName("Time");
                    columns.Bound(c => c.DoctorName).Title("Doctor");
                    columns.Command(command => { command.Edit(); }).Title("Edit").Width(250);
                    columns.Command(command => { command.Destroy(); }).Title("Delete").Width(150);
                })
                .Editable(editable => editable.Mode(GridEditMode.InLine))
                .Pageable()
                .Sortable()
                .Scrollable()
                .Events(events => events.Cancel("onCancel"))
                .DataSource(
                    dataSource => dataSource
                        .Ajax()
                        .Model(model =>
                        {
                            model.Id(a => a.PatAppointment.AppointmentId);
                            model.Field(a => a.DoctorName).Editable(false);
                        })
                        .Read("UpcomingAppointment_Read", "Appointment", new { PatientId = Model.PatAppointment.PatientId })
                        .Update(update => update.Action("UpcomingAppointment_Update", "Appointment"))
                        .Destroy(update => update.Action("UpcomingAppointment_Destroy", "Appointment"))
                )
    )​

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 23 Sep 2015 Link to this post

    Hello sanjay,

     

    We are sending the date object to the controller in the following format CustomDate: "/Date(1442359800000)/". 
     
    Based on the server culture settings a Date object will be created by the MVC model binder. MVC DateTime binding with incorrect date format discuss the same problem and provides a solution. 

     

     

     

     

    Regards,
    Boyan Dimitrov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. sanjay
    sanjay avatar
    3 posts
    Member since:
    Nov 2014

    Posted 23 Sep 2015 in reply to Boyan Dimitrov Link to this post

    Is there any way I can change the date before data is posted back to controller action? I mean to say change "/Date(1442359800000)/".  format on client side before data goes to server.
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 25 Sep 2015 Link to this post

    Hello sanjay,

    Maybe I am not quire sure that I understand the problem you are facing. I assume that the format of the Date is used for validation purposed on the server or something like that.

    If the property of the Grid model is defined as DateTime then the MVC model binder will parse the value and create a DateTime object. The DateTime object API could be used in order to access the month, date, time and etc values no matter of the format of the value sent from the client-side to the server. This information could be used in order to implement your validation or custom logic on the server. 

    Regards,
    Boyan Dimitrov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready