2

Using the example from Kendo's ComboBox: (ASP.NET MVC | template.cshtml)

@(Html.Kendo().ComboBox()
      .Name("customers")
      .DataTextField("ContactName")
      .DataValueField("CustomerID")
      .HtmlAttributes(new { style = "width: 400px" })
      .DataSource(source =>
      {
          source.Read(read =>
          {
              read.Action("GetCustomers", "Home");
          });
      })
      .Filter("startswith")
      .Height(300)
      .Template("<img src=\"" + Url.Content("~/Content/web/Customers/") + "${data.CustomerID}.jpg\" alt=\"${data.CustomerID}\" />" +
                        "<dl>" +
                            "<dt>Contact:</dt><dd>${ data.ContactName }</dd>" +
                            "<dt>Company:</dt><dd>${ data.CompanyName }</dd>" +
                        "</dl>")
)

Inside the Template if you want to use a value that is a DateTime, for example ${ data.StartDate } you would end up with something like this: 2012-06-13T00:00:00

What would the syntax be to format that to a readable Date inside that Template?

Shervin
  • 1,936
  • 17
  • 27
webwires
  • 2,572
  • 3
  • 26
  • 44

2 Answers2

0

The quick and dirty solution would be to create a new property that outputs your date as a string.

The more correct solution would be to feed the output of the property to a javascript date formatting function. You could use something like date.js.

Add this code:

"<dt>StartDate:</dt><dd>" + Date.parse('${ data.StartDate}').toString("M/d/yyyy") + "</dd>" +
Mark
  • 595
  • 5
  • 13
0

The best solution to your date formatting would be to create a DisplayTemplate at Views/Shared/DisplayTemplates/DateTime.cshtml

    @model DateTime

    @String.Format("{0:dd/MM/yyyy}", Model))

that would change it universally

source

Community
  • 1
  • 1
Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81