绑定到 MVC3 中的 DropDownList
以前,我在我的模型中使用它
public List<SelectListItem> StatusList { get; set; }
public string Status { get; set; }
,在我的视图中使用它来绑定到 Dropdownlist,
@Html.DropDownListFor(model => model.Status, Model.StatusList, "")
但如果我想使用
public List<ICode> StatusList { get; set; }
ICode 如下所示的位置,
public interface ICode
{
int Id { get; set; }
ICodeGroup CodeGroup { get; set; }
string ShortDescription { get; set; }
string LongDescription { get; set; }
}
我应该在我的视图和模型中做什么?
Previously, I was using this in my model
public List<SelectListItem> StatusList { get; set; }
public string Status { get; set; }
and this in my view to bind to the Dropdownlist
@Html.DropDownListFor(model => model.Status, Model.StatusList, "")
but if I want to use
public List<ICode> StatusList { get; set; }
where ICode is as below
public interface ICode
{
int Id { get; set; }
ICodeGroup CodeGroup { get; set; }
string ShortDescription { get; set; }
string LongDescription { get; set; }
}
What should I do in my view and model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Cybernate 的解决方案有效。您还可以这样做:
Cybernate 的版本将进行更强的类型检查,但 SelectList 更加封装。
Cybernate's solution works. You could also do:
Cybernate's version will do stronger type checking, but SelectList is more encapsulated.
试试这个:
Try this: