var timeList = new List<string>
{
"8.00 AM",
"8.15 AM",
"8.30 AM",
"8.45 AM",
"9.00 AM",
"9.15 AM",
"9.30 AM"
"17.00 PM"
};
ViewBag.TimeList = timeList;
是否有修改我的上述代码开始时间从8.00到17.00,间隔15分钟显示我的timeList?
这是我的View模型
@foreach (var T1 in ViewBag.TimeList)
{
@T1
}
我已经添加了我的代码@Value = @T1
,但它无效
@for (int i = 0; i < 3; i++)
{
@Html.EditorFor(m => m.Time, new { htmlAttributes = new { @class = "form-control myPicker", @Value = @T1 } })
<br />
<span id="mySpan-@i"></span>
}
任何人都可以告诉我如何在页面首次加载时自动填写网页表单时间间隔(例如,8.00,8.15..etc)。
答案 0 :(得分:1)
目前还不清楚ViewBag.TimeList
属性的用途是什么,但为了显示您的文本框,您需要设置模型的Time
属性的值。
在GET方法中
model.Time = new List<string>(){ "8.00 AM", "8.15 AM", "8.30 AM" }); // set the initial default values
....
return View(model);
并在视图中
for(int i = 0; i < Model.Time.Count; i++)
{
@Html.TextBoxFor(m => m.Time[i], new { @class = "form-control myPicker" })
}