在mvc中设置datepicker的默认日期

时间:2015-10-01 15:56:51

标签: asp.net-mvc datepicker

我已经在MVC网站上为我的datepicker实现了时刻js但我无法获得默认日期。我只是展示2015年1月1日。我希望它能显示今天的日期。

模型

public class TeamModel
{
    public Team Team { get; set; }
}

控制器。我设定了开始和结束日期:

model.Team = new Team();
model.Team.StartDate = DateTime.Today;
model.Team.EndDate = DateTime.Now.AddDays(30);

在我的视图中,我有js:

<script type="text/javascript">

    $(function () {
        moment.lang('da');
        $('#Team_StartDate').datetimepicker({
            locale: 'da',
        format: 'D-MMMM-YYYY',
        showClose: true,
        showClear: true,
        toolbarPlacement: 'top'
    });

        $('#Team_EndDate').datetimepicker({
            locale: 'da',
            format: 'D-MMMM-YYYY',
            showClose: true,
            showClear: true,
            toolbarPlacement: 'top'
    });
    });
</script>

和编辑

<div class="form-group">
            @Html.LabelFor(model => model.Team.StartDate, htmlAttributes:
new { @class = "control-label col-md-2" })
            <div>
                @Html.EditorFor(model => model.Team.StartDate, new {
                @Value = Model.Team.StartDate.ToString(), htmlAttributes = 
new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => 
model.Team.StartDate, "", new { @class = "text-danger" })
            </div>
        </div>

但StartDate中显示的日期为&#34; 1-januar-2015&#34;和&#34; 31-januar-2015&#34;在EndDate。

0 个答案:

没有答案