【发布时间】:2016-11-04 18:42:28
【问题描述】:
我有一个名为 Region 的简单模型,就像
namespace App
{
using System;
using System.Collections.Generic;
public partial class Region
{
public int RegionID { get; set; }
public string RegionDescription { get; set; }
}
}
我正在尝试将模型加载到 HTML DropDownListFor() 帮助程序中,例如
@model IEnumerable<App.Region>
<div class="row">
@Html.DropDownListFor("RegionList",
new SelectList(model => model.RegionDescription),
"Select Region",
new { @class = "form-control" })
</div>
或
@model IEnumerable<App.Region>
<div class="row">
@Html.DropDownListFor("RegionList",
new SelectList(s => s.RegionDescription),
"Select Region",
new { @class = "form-control" })
</div>
或:
@model IEnumerable<App.Region>
<div class="row">
@foreach (var item in Model)
{
@Html.DropDownListFor("RegionList",
new SelectList(model => item.RegionDescription),
"Select Region",
new { @class = "form-control" })
}
</div>
但在这两种情况下我都会收到此错误。
无法将 lambda 表达式转换为类型“对象”,因为它不是 委托类型
为什么会发生这种情况,我该如何解决?
【问题讨论】:
-
SelectList构造函数确实需要一个集合。不是 lamda 表达式。你从哪里得到这些信息的? -
嗨,谢谢Shyju的评论,我关注了
Link(tutorialsteacher.com/mvc/…) -
您提供的链接没有任何代码,例如您的问题!
-
这部分怎么样
@Html.DropDownListFor(m => m.StudentGender,