Last active
September 30, 2022 12:37
-
-
Save Eonasdan/1f6bd021319486e23777 to your computer and use it in GitHub Desktop.
MVC EditorFor Template for Datetimepicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.DataAnnotations; | |
[DataType(DataType.Time)] | |
public DateTime Updated { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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