简体   繁体   中英

How do you set a default valut to input type = date with c# MVC

I have a simple date field that i want to populate with a value from my database so my users can see the default before they edit:

<input type = "date" name = "Date" style = "width:180px;" value="@ViewBag.Options.Date"/>

Simply put, this doesnt popluate the date input. it works on all other forms of html5 inputs however, also worth noting that the ViewBag.Options.Date is a DateTime variable.

您的日期需要具有特定格式以使其明确:

@ViewBag.Options.Date.ToString("yyyy-MM-dd")

For every HTML input field, the browser will leave it empty unless a default value is specified with the value attribute.

currently HTML5 doesn't provide any way of specifying default date in the value attribute.

try some script may be it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM