ASP.NET MVC 2:手动创建列表并附加到模型
我有一个模型:
[Required]
public List<SelectList> Meals { get; set;
}
我想在我的控制器中创建一个列表,以便我可以将其附加到我的模型中的“餐食”。
由于某种原因,我在执行此操作时遇到了问题:
_model.MaxCoupons = new List<SelectListItem>();
SelectListItem _mList = new SelectListItem([]{
new SelectListItem { Text = "---", Value = "" },
new SelectListItem { Text = "50", Value = "50" },
new SelectListItem { Text = "60", Value = "60" },
new SelectListItem { Text = "70", Value = "70" },
new SelectListItem { Text = "80", Value = "80" },
new SelectListItem { Text = "90", Value = "90" },
new SelectListItem { Text = "100", Value = "100" },
new SelectListItem { Text = "110", Value = "110" },
new SelectListItem { Text = "120", Value = "120" },
new SelectListItem { Text = "130", Value = "130" },
new SelectListItem { Text = "140", Value = "140" },
new SelectListItem { Text = "150", Value = "130" } },
"Text", "Value" );
_model.MaxCoupons.Add(_mList);
我现在有点困惑......
I have a model:
[Required]
public List<SelectList> Meals { get; set;
}
And I want to create a list in my Controller so I can attach it to "Meals" in my Model.
For some reason I'm having issues doing this:
_model.MaxCoupons = new List<SelectListItem>();
SelectListItem _mList = new SelectListItem([]{
new SelectListItem { Text = "---", Value = "" },
new SelectListItem { Text = "50", Value = "50" },
new SelectListItem { Text = "60", Value = "60" },
new SelectListItem { Text = "70", Value = "70" },
new SelectListItem { Text = "80", Value = "80" },
new SelectListItem { Text = "90", Value = "90" },
new SelectListItem { Text = "100", Value = "100" },
new SelectListItem { Text = "110", Value = "110" },
new SelectListItem { Text = "120", Value = "120" },
new SelectListItem { Text = "130", Value = "130" },
new SelectListItem { Text = "140", Value = "140" },
new SelectListItem { Text = "150", Value = "130" } },
"Text", "Value" );
_model.MaxCoupons.Add(_mList);
I'm a bit confused right now...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
然后在一个方法中:
then inside a method: