0

Code in cshtml:

@Html.LabelFor(m => m.StartDateTime, new { @class = "lbl100" })
                    @Html.TextBoxFor(m => m.StartDateTime, "{0:yyyy-MM-dd}", new { @class = "form-control control120" })
                    @Html.LabelFor(m => m.EndDateTime, new { @class = "lbl100" })
                    @Html.TextBoxFor(m => m.EndDateTime, "{0:yyyy-MM-dd}", new { @class = "form-control control120" })

there are two ways to get this action, from menu with Ajax.Actionlink and form pagedlist actionlink

this is the value form menu: enter image description here

this is the value form pagedlist: enter image description here

why the format param not work?

Autyan
  • 111
  • 1
  • 12

1 Answers1

0

If plain String.Format inside TextBoxFor doesn't work, place formatting style using DisplayFormat on your DateTime model properties to enforce date input.

[DisplayName("Start Date")]
[DataType(DataType.Date)] // if HTML5 is used you can apply this attribute
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime StartDateTime { get; set; }

[DisplayName("End Date")]
[DataType(DataType.Date)] // if HTML5 is used you can apply this attribute
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime EndDateTime { get; set; }

Useful reference: Date only from TextBoxFor()

Community
  • 1
  • 1
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61