Click here to Skip to main content
15,889,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am assigning the date from kendo date pickerfor() but its not passing the selected date
selected date to controller but instead passing some default value

VB
@(Html.Kendo().DatePickerFor(model => model.DOB)
         .Name("dob")
//The name of the datepicker is mandatory. It specifies the "id" attribute of the widget.
.Value(DateTime.Today) //Set the value of the datepicker
             .Start(CalendarView.Year))
Posted

As mentioned at http://forums.asp.net/t/1958162.aspx?Null+value+when+passing+DateTime+value+from+View+to+Controller, you can add data handler as:

.Update(update => update.Action("Edit", "YourControllerName", new { entity = Model }).Data("onUpdateRequest_Details"))

Then specify the fumction body as:

C#
function onUpdateRequest_Details(e) {
    e.LastStatementDate = $("#<YourDateFieldName>").val(); // set string value
}


This will convert value from date to string and pass string.

Possibly, the following is not necessary (I removed DisplayFormat and ApplyFormatInEditMode, and the value was still passed correctly):

C#
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime? <YourDateFieldName> { get; set; }
 
Share this answer
 
VB
@(Html.Kendo().DatePickerFor(model => model.DOB)
         
//The name of the datepicker is mandatory. It specifies the "id" attribute of the widget.
.Value(DateTime.Today) //Set the value of the datepicker
             .Start(CalendarView.Year))


Try this code
 
Share this answer
 
Comments
Member 10934676 2-Sep-15 6:48am    
Hello Member of Solution 2. This really helped me. Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900