22

I want to change this code from MVC2

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>

  <%=Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" }) %>

To MVC 3 using Razor.

You can find the full post of what I want to do here

Mathieu
  • 4,449
  • 7
  • 41
  • 60
roncansan
  • 2,310
  • 6
  • 27
  • 34

1 Answers1

41
@model DateTime?

@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" })
Fabian
  • 13,603
  • 6
  • 31
  • 53
  • 1
    Can anybody drop a link to the datePicker jQuery file? – M Kenyon II Jun 21 '12 at 19:51
  • +1 The first parameter is supposed to be the name of the textbox field right? I assume that it will default by some mechanism to the correct value if it's passed an empty string... – Lzh Oct 20 '13 at 21:18