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

post dates from asp.net mvc to controller

3 Answers 287 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sanjay
Top achievements
Rank 1
sanjay asked on 20 Sep 2015, 02:54 PM

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"))
            )
)​

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 23 Sep 2015, 11:40 AM

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
0
sanjay
Top achievements
Rank 1
answered on 23 Sep 2015, 01:33 PM
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.
0
Boyan Dimitrov
Telerik team
answered on 25 Sep 2015, 11:09 AM

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
Tags
Grid
Asked by
sanjay
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
sanjay
Top achievements
Rank 1
Share this question
or