數據的名單我想有一個可以在視圖上視圖模型和下拉菜單中使用的模型數據的靜態列表。我希望能夠使用它以這種方式在我的控制器:靜態下拉列表中MVC
MaintenanceTypeList = new SelectList(g, "MaintenanceTypeID", "MaintenanceTypeName"),
和訪問它在我的觀點是這樣的:
@Html.LabelFor(model => model.MaintenanceTypeID)
@Html.DropDownListFor(x => x.MaintenanceTypeID, Model.MaintenanceTypeList, "-- Select --", new { style = "width: 150px;" })
@Html.ValidationMessageFor(x => x.MaintenanceTypeID)
我目前使用的存儲庫模式對數據庫中的數據,但不希望將這些數據放入數據庫中,因爲它永遠不會改變。儘管我仍然希望它在模型中。基本上,我的下拉列表中應具備以下特徵:使用模型靜態列表的
Value Text
-------------------------------------
Calibration Calibration
Prevent Preventative Maintenance
CalibrationPrevent PM and Calibration
任何幫助或例子/ OOP認識
謝謝!我對你的第一個建議採取了非常類似的路線,所以我將其標記爲答案。我在這裏找到了解決方案:http://www.dotnetcurry.com/ShowArticle.aspx?ID=584 – steveareeno