DatePicker Editor Template - ASP.NET MVC

Usage

Within a Razor view for a model with a DateTime property

@Html.EditorFor(m => m.MyDateTimeProperty, "DatePicker")

Reusable Code

Razor Markup

Create a Razor view called "DatePicker.cshtml" within your /Views/Shared/EditorTemplates folder

@model System.DateTime
@{
    ViewData["class"] = ViewData["class"] + " datepicker";
}
@Html.TextBoxFor(m => m, "{0:MM/dd/yyyy}", ViewData)

JavaScript

This assumes you have jQuery UI loaded.

$('.datepicker').datepicker()