Skip to content

Instantly share code, notes, and snippets.

@badcommandorfilename
Created July 20, 2017 01:24
Show Gist options
  • Save badcommandorfilename/118012102de8e7201e079e519ee9d135 to your computer and use it in GitHub Desktop.
Save badcommandorfilename/118012102de8e7201e079e519ee9d135 to your computer and use it in GitHub Desktop.
C# HTML5 input date datepicker MVC Razor
<!-- How to insert a date editor in a Razor view -->
<div class="form-group">
@Html.LabelFor(model => model.Start, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Start, new { @type="date", @class = "form-control datepicker", @Value = Model.Start.ToString("yyyy-MM-dd") } )
@Html.ValidationMessageFor(model => model.Start, "", new { @class = "text-danger" })
</div>
</div>
@edisoncpp
Copy link

edisoncpp commented Jan 5, 2019

Thanks! The @Value part made mine work!

@mynameisgenesis
Copy link

I agree! Thank you! I just used the @type="date".

@AlexTinbSys
Copy link

Thanks!

@osama9988
Copy link

Thanks, you are life Saver

@dachieu1996
Copy link

Thank you so much

@amarckant-dey
Copy link

Thanks for the help!!!

@sajeeshuni
Copy link

Dear team,
I need to implement datetime picker in MVC-Razor.

any bootstrap css is there for supporting Date-Time picker

@jayD-its
Copy link

Thanks a lot for this. It came very handy. But how can I refer to the values of model.start for future?

@interfacesysolucionesfholguin

Thanks Friend for you Help.

@Xian81
Copy link

Xian81 commented Feb 18, 2021

Thank for this. I have been searching for ages how to do this with database first. Here it is !

@AbhayBabariya
Copy link

Thank you Bro, in edit time do not auto-fill date I have wast one day but your code is work.

@warlod
Copy link

warlod commented Aug 11, 2022

Gracias!

@EissaAbdellah
Copy link

Thanks Friend for you Help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment