I want to use Data Picker for a datatime field in my MVC-Form
I am using the Following code to get the Data time value,
[Required(ErrorMessage="Please enter the Absence Start Date")]
[StringLength(20,ErrorMessage="The Format must not exceed 50 Characaters")开发者_C百科]
[DataType(DataType.DateTime )]
[Display(Name="Absence Start Date")]
public DateTime AbsenceStartDate{get;set;}
But I want to have datapicker controls beside the textbox. How could I do that?
Any help
Thank you
A good client-side datepicker is provided in the jQuery UI library: http://jqueryui.com/demos/datepicker/
You may use jQuery UI datepicker with DateTime editor template in asp.net mvc. Take a look at Sample. Actually, you SHOULD use editor-template
I would use a client-side date picker. There are plenty available for jQuery. Then you use ASP.NET MVC to validate the input as text in the form of a date..
You can create an extension method as below:
public static MvcHtmlString CalenderTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
{
return htmlHelper.TextBoxFor(expression, "{0:M/dd/yyyy}", new { @class = "datepicker text" });
}
Then use in view as below:
@Html.CalenderTextBoxFor(model => model.Employee.HireDate)
精彩评论