0

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")]
    [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

4 Answers 4

1

A good client-side datepicker is provided in the jQuery UI library: http://jqueryui.com/demos/datepicker/

0
1

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

0

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..

0

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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.