I've created a extension method of Jquery datepicker, below are the source code.
public static string DatePicker(this HtmlHelper htmlHelper, string name, DateTime? value)
{
if (!string.IsNullOrEmpty(name))
{
return "<script type=\"text/javascript\">"
+ "$(function() {"
+ "$(\"#" + name +
"\").datepicker({changeMonth: true,changeYear: true, dateFormat: 'dd/mm/yy', duration: 0});"
+ "});"
+ "</script>"
+ "<input type=\"text\" size=\"10\" value=\""
+ FormattedDate(value)
+ "\" id=\""
+ name.Replace('.', '_')
+ "\" name=\""
+ name + "\"/>";
}
return string.Empty;
}
I have used the above extension method in the View.
<div class="editor-label">
@Html.LabelFor(model => model.Committee.AppointedDate)
</div>
<div class="editor-field">
@Html.Raw(Html.DatePicker("CommitteeAppointedDate", Model.Committee.AppointedDate))
@Html.ValidationMessageFor(model => Model.Committee.AppointedDate)
</div>
When I click on submit button, the view model which is holding above appointed date is showing DateTime.MinValue at the controller action method.
Please let us know what's wrong with the above code.
StringBuilder, not string concatenation.