这是我的观点..
<div style="float: left; width: 450px; text-align:left; margin-left:80px">
<div class="row">
<div class="label" style="float: left; width: 80px">Date From: </div>
<div class="control">
@Html.EditorFor(model => model.DateFrom, new { ID = "datefrom" })
@Html.ValidationMessageFor(model => model.DateFrom, null, new { style = "color: red" })
</div>
</div>
<div class="row">
<div class="label" style="float: left; width: 80px">Date To: </div>
<div class="control" >
@Html.EditorFor(model => model.DateTo, new { ID = "dateto" })
@Html.ValidationMessageFor(model => model.DateTo, null, new { style = "color: red" })
</div>
</div>
<div><input type="checkbox" id="relative" name="relative" onclick="validate()" />Is Relative</div>
</div>
这是我的js函数:
function validate() {
if (document.getElementById('relative').checked) {
document.getElementById('@Html.IdFor(model => model.DateFrom)').disabled = true;
document.getElementById('@Html.EditorFor(model => model.DateFrom, new { @Value = DateTime.Now })');
document.getElementById('@Html.IdFor(model => model.DateTo)').disabled = true;
document.getElementById('@Html.EditorFor(model => model.DateTo, new { @Value = DateTime.Now })');
} else {
document.getElementById('@Html.IdFor(model => model.DateFrom)').disabled = false;
document.getElementById('@Html.IdFor(model => model.DateTo)').disabled = false;
}
}
如何为Html.EditorFor分配默认值(DateTiem.Now)?非常感谢你的帮助!!!
答案 0 :(得分:0)
No Body在很长一段时间内都回复了这个问题。如果其他人试图解决类似的问题。
在您的Javascript中尝试此操作。
document.getElementById('@Html.IdFor(model => model.Draw)')