Will Nick Clark respond to work when you send values ββvia postback?
In MVC2 preview 2, calling Html.Textbox ("abc", Model.ToString ()) will display a text box with ".abc" appended to the name, for example.
<input id="StartDate_abc" name="StartDate.abc" type="text" value="02 Feb 09" />
which will cause problems with postback and trying UpdateModel ().
I made an editor template for DateTime, the following works for me:
/Views/Shared/EditorTemplates/DateTime.ascx:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %> <%= Html.TextBox(String.Empty, Model.ToString("dd MMM yy")) %>
or, to use jQuery DatePicker for all your DateTimes, add a link to jQuery and jQueryUI either to the main page or to the view containing the EditorFor call.
/Views/Shared/EditorTemplates/DateTime.ascx:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %> <%= Html.TextBox("", Model.ToString("dd MMM yy")) %> <script type="text/javascript"> $("#<%= ViewData.ModelMetadata.PropertyName %>").datepicker({ dateFormat: 'dd M y' }); </script>
Update: ASP.NET MVC3 using Razor syntax:
@model System.DateTime @Html.TextBox("", Model.ToString("dd MMM yy")) <script type="text/javascript"> $("#@ViewData.ModelMetadata.PropertyName").datepicker({ dateFormat: 'dd M y' }); </script>
And use all you need in your view is:
@Html.EditorFor(model => model.DueDate)
Matt
Matt frear
source share