Asp.net mvc 5 kendo datetimepicker未将值设置为viewmodel
我正在MVC5应用程序中实现剑道日期选择器。我不确定viewmodel属性未设置为datetimepicker中所选内容的原因Asp.net mvc 5 kendo datetimepicker未将值设置为viewmodel,asp.net-mvc-5,kendo-asp.net-mvc,kendo-datetimepicker,Asp.net Mvc 5,Kendo Asp.net Mvc,Kendo Datetimepicker,我正在MVC5应用程序中实现剑道日期选择器。我不确定viewmodel属性未设置为datetimepicker中所选内容的原因 <div class="form-group"> @Html.LabelFor(model => model.ContractStartDate, htmlAttributes: new { @class = "control-label col-md-5" }) <
<div class="form-group">
@Html.LabelFor(model => model.ContractStartDate, htmlAttributes: new { @class = "control-label col-md-5" })
<div class="col-md-6">
@*@Html.EditorFor(model => model.ContractStartDate, new { htmlAttributes = new { @class = "form-control" } })*@
@(Html.Kendo().DatePickerFor(model => model.ContractStartDate)
.Name("contractdatepicker")
.Value("10/10/2011")
.HtmlAttributes(new { style = "width: 100%" })
)
@Html.ValidationMessageFor(model => model.ContractStartDate, "", new { @class = "text-danger" })
</div>
</div>
@LabelFor(model=>model.ContractStartDate,htmlAttributes:new{@class=“controllabel col-md-5”})
@*@EditorFor(model=>model.ContractStartDate,new{htmlAttributes=new{@class=“form control”}})*@
@(Html.Kendo().DatePickerFor(model=>model.ContractStartDate)
.名称(“合同日期选择器”)
.价值(“2011年10月10日”)
.HtmlAttributes(新的{style=“width:100%”)
)
@Html.ValidationMessageFor(model=>model.ContractStartDate,“,new{@class=“text danger”})
问题在于您的.Name(“contractdatepicker”)
。渲染后,它将成为
上的名称和id标记,因此不会绑定到viewmodel。如果省略该属性,它将自动添加名称和idContractStartDate
。因此,只需删除该标记,如果在javascript中引用它,请将引用更改为#ContractStartDate