Skip to content

Instantly share code, notes, and snippets.

@Eonasdan
Last active September 30, 2022 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eonasdan/1f6bd021319486e23777 to your computer and use it in GitHub Desktop.
Save Eonasdan/1f6bd021319486e23777 to your computer and use it in GitHub Desktop.
MVC EditorFor Template for Datetimepicker
using System.ComponentModel.DataAnnotations;
[DataType(DataType.Time)]
public DateTime Updated { get; set; }
//This file goes in /Shared/EditorTemplates/Time.cshtml
//You can easily do this for DataType.Date and DataType.DateTime
@{
var attributes = new Dictionary<string, object>();
attributes.Add("class", "form-control");
attributes.Add("type", "datetime");
}
<div class="input-group timepicker col-sm-3 col-md-3" id="@(ViewData.TemplateInfo.HtmlFieldPrefix)-timepicker">
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, attributes)
<span class="input-group-addon">
<span class="fa fa-clock-o"></span>
</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment