Model中定义的DateTime属性始终在Controller中给出默认值

时间:2017-05-24 11:22:07

标签: c# asp.net-mvc

型号:

 public class BR_Model
{
    public string State { get; set; }

    [Required]
    public DateTime date { get; set; }
    public List<SelectListItem> list { get; set; }

}

查看:

   <div class="row">
   <div class="col-lg-3 col-md-3 col-sm-12">
   @Html.DropDownListFor(m => m.State, ViewBag.StateList as   IEnumerable<SelectListItem>, new { @class = "form-control  input-sm", @onchange = "this.form.submit()" })
   </div>
   <div class="col-lg-3 col-md-3 col-sm-12">
   @Html.ValidationMessageFor(m => m.date)
   @Html.TextBoxFor(m => m.date, new { @class = "form-control input-sm", @id = "dp1", @PlaceHolder = "Click Here to Select a Date" })
   </div>
</div>

控制器:

DateTime dd = obj.date;
string state = obj.State;
string Date = dd.Date.ToString("yyyy-MM-dd");

我得到的是州的价值而不是约会,它总是01-01-0001 我不知道我在这里做错了什么 See image here

更新问题: 经过一番调查后我得到了这个错误 enter image description here

日期字段使用bootstarp javascript,没有任何选项

  $('#dp1').datepicker( );

0 个答案:

没有答案