【发布时间】:2016-04-10 15:14:51
【问题描述】:
我在 MVC 中有一个模板 TimeSpan。
查看
@model TimeSpan?
@{
var id = "id" + Guid.NewGuid().ToString().Substring(0, 5);
string format = (string)(this.ViewData["format"] ?? @"hh\:mm\:ss");
IEnumerable<SelectListItem> listValues;
if (this.Model.HasValue)
{
listValues = from x in Enumerable.Range(0, 96)
.Select(x => new TimeSpan(9000000000 * x))
.Select(x => new SelectListItem {Selected = true, Value = x.ToString(),
Text = x.ToString(format) })
}
else
{
listValues = from x in Enumerable.Range(0, 96)
select new SelectListItem { Value = x.ToString(),
Text = x.ToString(format) };
}
}
<div class="field-small">
@Html.DropDownListFor(x => x, listValues, new { id = id})
</div>
<script type="text/javascript"">
$("#@id")
.turnAutoComplete();
</script>
但有例外
select 子句中的表达式类型不正确。类型 调用“Select”时推理失败。
和
查询正文必须以 select 子句或 group 子句结尾
线路错误
listValues = from x in Enumerable.Range(0, 96)
.Select(x => new TimeSpan(9000000000 * x))
.Select(x => new SelectListItem { Selected = true, Value = x.ToString(),
Text = x.ToString(format) })
我不知道我的线路出了什么问题
【问题讨论】:
标签: c# html sql asp.net-mvc-4