0

我有一个窗体,它发送到强类型视图中的控制器。 的观点是一种 “shitModel” 具有 “shitType” 的名单模型的绑定列表作为模型的属性

型号:

public class shitModel { 
    public string name; 
    public List<shitType> types; 
} 

查看:

should contain listboxfor model.types 

什么想法?对你的看法感谢

+0

通过列表框你的意思是一个HTML选择框? – Samin 2013-05-07 11:56:59

+0

检查[这里](http://www.asp.net/mvc/tutorials/javascript/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc) – 2013-05-07 12:05:59

+0

Html.Listboxfor – user786701 2013-05-07 12:16:59

回答

0

写下面的代码,如果它是一个Razor视图

@*i am considering you have Name and ID members in your shitType class*@ 
@Html.DropDownList("shitTypes", Model.types.Select(t=> new SelectListItem{ Text = t.Name, Value = t.ID})) 
+0

但是由于值是id,它不会仅保存列表而不是整个shitType? – user786701 2013-05-07 12:03:01

+0

你在你的模型中提到了shitType :) 任何你可以实现的方式,但是对于Text和Value属性具有相同的String值。 – 2013-05-07 12:29:06

+0

但我不需要名单,我需要名单我并没有低估你 – user786701 2013-05-07 12:36:13