简体   繁体   English

为什么我的EditorFor datepicker字段没有填充我的值?

[英]Why isn't my EditorFor datepicker field populating my value?

I'm trying to get this datepicker field to populate with today's date but it's not happening for some reason. 我正在尝试让此datepicker字段填充今天的日期,但是由于某种原因没有发生。 I can't find a reference for what options are accepted in the "new {}" section. 我在“新{}”部分找不到有关接受哪些选项的参考。

@Html.LabelFor(d => d.ServiceOn, new { @class = "control-label" })
@Html.EditorFor(d => d.ServiceOn, "DatePicker", new { disableMinDate = true, Value = DateTime.Today })
@Html.ValidationMessageFor(d => d.ServiceOn, "", new { @class = "text-danger" })

I've tried value, Value and @Value but the resulting html always shows value="". 我已经尝试过value,Value和@Value,但是生成的html总是显示value =“”。 I'm wondering if maybe the datepicker itself is zeroing out the field. 我想知道日期选择器本身是否正在将该字段清零。 I feel like I'm missing something obvious here. 我觉得这里缺少明显的东西。

This should work: 这应该工作:

@Html.LabelFor(d => d.ServiceOn, new { @class = "control-label" })
@{Model.ServiceOn= DateTime.Today;}
@Html.EditorFor(d => d.ServiceOn, "DatePicker", new { disableMinDate = true })
@Html.ValidationMessageFor(d => d.ServiceOn, "", new { @class = "text-danger" })

HTML work with the ModelState , not from the model itself. HTML使用ModelState而不是模型本身。

If you want more loose helpers, ise @Html.Editor instead. 如果您需要更多的宽松助手,请使用@Html.Editor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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