c# - MVC project: Convert user input date mmddyyyy to yyyy/mm/dd -
i have textbox in mvc project prompts user enter date mmddyyyy. have code set user can input numbers (ie, no "/"s or "-"s). need convert data yyyy-mm-dd ensure correct data being added database once form submitted.
i realize need use datetime.parse this, can't life of me figure out how add following code:
<div class="form-group"> @html.labelfor(model => model.buy2idexpiredate, htmlattributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @html.textboxfor(model => model.buy2idexpiredate, new { id = "cobuyeridexpiredate", @class = "form-control" }) @html.validationmessagefor(model => model.buy2idexpiredate, "", new { @class = "text-danger" }) </div> </div> would this?
string str = date.parse(buy2idexpiredate).tostring("yyyy-mm-dd"); if put in above code, , need write code ensure newly formatted date stored database?
you can add value attribute this:
@html.textboxfor(model => model.buy2idexpiredate, new { @value = model.buy2idexpiredate.tostring("yyyy-mm-dd") })
Comments
Post a Comment