You can add a hidden input field to the page. Using the altField and altFormat , you can send data to your page in an alternative format.
To do this, you can create your own editor template for the DateTime format. Add the DateTime.cshtml file to the Views / Shared / EditorTemplates folder.
Then you can use this content (not verified):
@model DateTime? @using System.Globalization @{ var name = MvcHtmlString.Create(ViewData.TemplateInfo.GetFullHtmlFieldName("")); var id = MvcHtmlString.Create(ViewData.TemplateInfo.GetFullHtmlFieldId("")); var visibleID = id + "_editor"; var value = Model ?? DateTime.Today; var formattedValue = value.ToString("dd MMM yyyy"); } <input type="text" id="@(visibleID)" value="@formattedValue" /> <input type="hidden" id="@(id)" name="@(name)" value="@value.ToString("yyyy/MM/dd")" /> <script type='text/javascript'> $(function () { $('#@(visibleID)').datepicker({ dateFormat: 'd mm y', altField='@id', altFormat='d/m/y' }); }); </script>
Then you need to use only TextBoxFor, in any DateTime field the datetimepicker will be activated.
source share