【问题标题】:Bootstrap datepicker not popping out in MVC引导日期选择器未在 MVC 中弹出
【发布时间】:2015-04-01 14:50:39
【问题描述】:

我看到很多关于这个的帖子,但无法解决。

在我看来,引导日期选择器已成功弹出输入标签 例如:

<input class="span2 datepicker" size="16" type="text" value="12-02-2012">

当我运行页面时,我可以通过 datepicker 更改日期。

$(document).ready(function () {
            $('.datepicker').datepicker();
        });

但同样不适用于以下代码

<div class="control-group">@Html.LabelFor(model => model.dob, htmlAttributes: new { @class = "control-label " })
<div class="controls">
 @Html.EditorFor(model => model.dob, new { htmlAttributes = new {@class = "datepicker" } })
@Html.ValidationMessageFor(model => model.dob, "", new { @class = "field-validation-error text-danger" })
</div>
</div>

请帮帮我。

【问题讨论】:

    标签: asp.net-mvc datepicker bootstrap-datepicker


    【解决方案1】:

    整理好了

    <div class="control-group">@Html.LabelFor(model => model.dob, htmlAttributes: new { @class = "control-label " })
    <div class="controls">
     @Html.EditorFor(model => model.dob, new {@class = "datepicker" } })
    @Html.ValidationMessageFor(model => model.dob, "", new { @class = "field-validation-error text-danger" })
    </div>
    </div>

    我从Editorfor 中删除了new { htmlAttributes =

    它的工作正常:)

    【讨论】:

    • @Html.EditorFor(model =&gt; model.dob, new {@class = "datepicker" } }) 不添加 class 属性(检查您生成的 html)所以除非您有一个自定义 EditorTemplate 用于 DateTime 这意味着您呈现 HMTL5 日期选择器,而不是引导程序日期选择器
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-06
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多