模型的绑定列表作为模型的属性
我有一个窗体,它发送到强类型视图中的控制器。 的观点是一种 “shitModel” 具有 “shitType” 的名单模型的绑定列表作为模型的属性
型号:
public class shitModel {
public string name;
public List<shitType> types;
}
查看:
should contain listboxfor model.types
什么想法?对你的看法感谢
写下面的代码,如果它是一个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}))
但是由于值是id,它不会仅保存列表
你在你的模型中提到了shitType :) 任何你可以实现的方式,但是对于Text和Value属性具有相同的String值。 – 2013-05-07 12:29:06
但我不需要名单
通过列表框你的意思是一个HTML选择框? – Samin 2013-05-07 11:56:59
检查[这里](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
Html.Listboxfor – user786701 2013-05-07 12:16:59