我的DropDownListFor有问题,我想要一个1,2,3,4,5等等的DropDownlist。
在我的模特课上:
public class PageModel
{
[DisplayName("Quantity")]
public int Quantity { get; set; }
}我创建了一个Quantity类
public class Quantity
{
public int Selection { get; set; }
}HtmlList类
public static class HtmlLists
{
public static IEnumerable<Quantity> Selections = new List<Quantity> {
new Quantity {
Selection = 1
},
new Quantity {
Selection = 2
}
};在我看来:
@Html.LabelFor(m => m.Quantity):
<td>@Html.DropDownListFor(m => m.Quantity, new SelectList(HtmlList.Selections, "Selection"))这让我在HtmlList.Selections犯了个错误
名称“HtmlList”在当前上下文中不存在
编辑:
我的错误问题用@using YourNameSpaceofStaticClass修正了
但现在我有了个问题:
他没有向我展示下拉列表中的第1和第2项,而是向我展示:
ModelNamespace.Quantity ModelNamespace.Quantity
我想这是因为我的名单是空的。
我的Quantity类的命名空间:
namespace ModelNamespace
{发布于 2013-03-18 08:24:10
您需要在视图中包含静态类的命名空间。
@using RandomProject.Helpers;还有一个建议,您可以在视图模型中创建一个属性,而不是创建静态类。
public class yourViewModel
{
public IEnumerable<Quantity> Selections {get;set;}
}https://stackoverflow.com/questions/15472317
复制相似问题