I am working on an MVC project and using jquery datepicker I am having problems with this post. I am using a partial view that contains a text box and a jquery function. Like this:
@model Nullable<System.DateTime>
<div class="row-fluid input-append">
@if (Model.HasValue && Model.Value != DateTime.MinValue)
{
@Html.TextBox("", String.Format("{0:dd/MM/yyyy}", Model.Value), new { @class = "input-small date-picker",@readonly = true, style = "cursor:pointer; background-color: #FFFFFF; text-align: center;" })
}
else
{
@Html.TextBox("", String.Format("{0:dd/MM/yyyy}", ""), new { @class = "input-small date-picker", @readonly = true, style = "cursor:pointer; background-color: #FFFFFF; text-align: center;" })
}
</div>
@{
string name = ViewData.TemplateInfo.HtmlFieldPrefix;
string id = name.Replace(".", "_");
}
<script type="text/javascript">
$('#@id').datepicker({
dateFormat: 'dd/mm/yy',
todayHighlight: true,
clearBtn: true,
forceParse: true,
autoclose: true,
});
</script>
When I format the datepicker to select a date in days / months / years, and when I select a date in a format, that's fine! I mean, I select August 5th in the calendar, and the text box shows 05/08/2013, but the problem arises when the click is saved, because in the controller the date value changes from several months to several months! Thank!
source
share