为什么我的 textBoxFor type="date" 不显示日期?

Why my textBoxFor type="date" doesn't display date?

我有一个简单的局部视图,其中有一个 TextBoxFor type = "date"(日期选择器)。 当我打开这个部分视图时,我希望 TextBoxFor type = "date" 显示模型中的日期。 但是我无法访问它,TextBoxFor 什么都不显示。

Model.Dt_Reference 很好地显示在 ViewBag.Title 中。

这是部分视图:

    @using w_TreatmentMVC.Models
@model w_TreatmentMVC.Models.DemandeModel
@{
    Layout = null;
}
@{
    ViewBag.Title = "Modif demand n° " + Model.ID_DEMAND + " : " + Model.LI_TREATMENT + " : " + Model.DT_REFERENCE;
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

<script type="text/javascript" src="../../Scripts/GlobalScripts.js"></script>

<div class="form-group">

    @Html.TextBoxFor(m => m.DT_REFERENCE, new { @type = "date", @Value = Model.DT_REFERENCE.ToString("dd/MM//yyyy") })

</div>

<div class="col-lg-12 col-md-12 col-xs-12" id="divPartial">
    <div class="col-lg-12 col-md-12 col-xs-12" id="divDemandOption">

        @Html.Action("SearchDemandOption", "Option")
    </div>
</div>
<input id="ButtonClose" type="button" value="Close" onclick="fctClose()" />

<script>

    function fctClose() {
        $("#divPopUpModal").fadeOut("slow");
        $('#divMainModal').fadeOut("slow");
    }
</script>

你能帮帮我吗?

非常感谢。

埃里克

如果要为日期输入设置默认值,其值格式需要为 value="yyyy-mm-dd"。如果您的 DT_REFERENCE 是日期时间类型,请尝试这样做:

<input type="date" asp-for="DT_REFERENCE" value=@Model.DT_REFERENCE.ToString("yyyy-MM-dd").Split(" ")[0] />

结果: