I am trying to bind the selected date from the jQueryUI datepicker to the model to be used in the controller, but its returning null. I am able to retrieve the selected value when formcollection is used
ViewModel
public class EmpViewModel
{
public int EmpId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
}
View
<div class="col-md-10">
@Html.EditorFor(model => model.DateOfBirth,
new { htmlAttributes = new { @class = "form-control datefield" } })
</div>
Controller
public ActionResult Create(EmpViewModel emp)
{
}
Tried the method in the below article but couldn't get it working http://www.asp.net/mvc/overview/older-versions/using-the-html5-and-jquery-ui-datepicker-popup-calendar-with-aspnet-mvc/using-the-html5-and-jquery-ui-datepicker-popup-calendar-with-aspnet-mvc-part-4
Script
<script>
$(function () {
$(".datefield").datepicker();
})
</script>