【问题标题】:mvc How can pick up month and year?mvc 怎样才能取到月份和年份?
【发布时间】:2019-05-13 10:52:59
【问题描述】:

DatePicker 你好,我想用月份和年份替换这个日期选择器。在我的模型中,我有这段代码:

[Required]
        [DataType(DataType.Date)]
        [Display(Name = "Select Month")]
        [DisplayFormat(DataFormatString = "{0:MM/yyyy}", ApplyFormatInEditMode = true)]
        public Nullable<System.DateTime> Month { get; set; }

在我看来我有这个:

<div class="col-sm-9">

                        Current Month :  <span>@Convert.ToDateTime(Model.Month).ToString("MMM-yyyy")</span>
                        @Html.EditorFor(model => (model.Month), new { htmlAttributes = new { @class = "form-control input-circle " } })
                        @Html.ValidationMessageFor(model => model.Month, "", new { @class = "text-danger " })
                    </div>

【问题讨论】:

标签: asp.net-mvc datepicker


【解决方案1】:

在你看来

@Html.TextBoxFor(a => a.model.Month, "{0:MM/yyyy}", new { @class = "form-control"})

添加 JqueryUi 脚本。

$(function () {
$("#Month").datepicker();
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 2016-04-05
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    相关资源
    最近更新 更多