Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBoxFor show date without time

I want to show date in text field in format MM/dd/yy. I described model class as:

public class VacancyFormViewModel
{
    public int? ID { get; set; }
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yy}")]
    public DateTime SurgeryDate { get; set; }

Of course, I can use EditorFor instead of TextBoxFor:

@Html.EditorFor(p => p.SurgeryDate, new { @class = "form-control" })

Problem is css styles, customer wants apply bootstrap styles, which are broken:

enter image description here

if I set TextBoxFor instead of EditorFor I get the date with time:

@Html.TextBoxFor(p => p.SurgeryDate, new { @class = "form-control" })

enter image description here

Any way to solve my problem? Or apply styles for EditorFor, or show TextBoxFor without time, or third way?

like image 972
Oleg Sh Avatar asked Aug 31 '26 09:08

Oleg Sh


1 Answers

You can specify date format in TextBoxFor helper like this:

@Html.TextBoxFor(m => m.SurgeryDate, "{0:MM/dd/yy}",  new { @class = "form-control" })
like image 143
teo van kot Avatar answered Sep 02 '26 15:09

teo van kot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!