ASP.NET MVC凡保留值SelectLists [英] ASP.NET MVC Where to keep the values for SelectLists
本文介绍了ASP.NET MVC凡保留值SelectLists的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前得到了这一切混乱的在我的ViewModels,我觉得违反了DTO的目的的顶部。例如,这是我认为的车型之一的构造 -
I've currently got all of this mess at the top of my ViewModels which I feel violates the purpose of a DTO. For example, this is in the constructor of one of my view models -
Dictionary<int, string> chargeGroups = new Dictionary<int, string>();
chargeGroups.Add(1, "Administration");
chargeGroups.Add(2, "Annual Leave");
chargeGroups.Add(3, "Bereavement");
chargeGroups.Add(4, "Customer Installation, Setup & Training");
chargeGroups.Add(5, "Customer Support");
chargeGroups.Add(6, "Internal Training & Education");
chargeGroups.Add(7, "Sales & Marketing");
chargeGroups.Add(8, "Sick");
chargeGroups.Add(9, "Software Devel / Maint / Test");
chargeGroups.Add(10, "Software Upgrade / Patch");
chargeGroups.Add(11, "Other");
chargeGroups.Add(12, "Other Absence");
chargeGroups.Add(13, "Warranty");
chargeGroups.Add(14, "Public Holiday");
chargeGroups.Add(15, "Other Paid Leave");
ChargeGroups = new SelectList(chargeGroups, "Key", "Value");
我的视图模型:
[DisplayName("Charge group")]
public short? ChargeGroup { get; set; }
public SelectList ChargeGroups;
然后在我看来:
<div class="editor-label">
@Html.LabelFor(model => model.ChargeGroup)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.ChargeGroup, Model.ChargeGroups)
@Html.ValidationMessageFor(model => model.ChargeGroup)
</div>
在哪里,我应该把这个东西吗?
Where should I be putting this stuff?
推荐答案
我决定保留值名为OtherData另一类它坐落在我的模型文件,我的主要的DbContext类旁边的选择列表中。
I decided to keep the values for the select list on another class called OtherData which sits beside my main DBContext class in my models file.
这篇关于ASP.NET MVC凡保留值SelectLists的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文