1
我目前正在学习C#.net,我试图显示一个不同的状态列表,但我无法弄清楚如何做到这一点。显示字符串列表
在我的控制,我有:
public ActionResult StateListDistinct()
{
var distinctStates = (from w in db.Contact_Addresses
select new { State = w.Site_address_state}).Distinct();
return View(distinctStates.ToList());
}
在我看来,我有:
@model List<String>
<table class="table">
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(model => item)
</td>
</tr>
}
</table>
我越来越
模型项目传递到字典中的错误是类型'System.Collections.Generic.List`1 [<> f__AnonymousType1`1 [System.String]]',但是这个字典需要一个ty的模型项pe'System.Collections.Generic.List`1 [System.String]'。
我需要做些什么来显示状态列表?
'选择新w.Site_address_state'假设Site_address_state是字符串类型。 –