I personally believe that database management is the way to go. Mostly from experience, let's say you wanted to add a value to your search, and you have already deployed your application, you will have to redeploy the code after adding a new value to Enum. Due to the fact that they are managed by the database, you can simply run the insert request to the database, and redeployment is not required.
I would not call your database in your view like this, although I would not say that this is the best practice, since it is not the responsibility to browse, it just needs to display the data, and not request additional data.
First of all, place your items in your drop-down list in your model, for example:
public class YourModel { public int WidgetTypeId { get; set; } public SelectList WidgetTypes { get; set; }
Then, in your GET method in your controller (before returning your view, fill this list with the code that you have in the view:
public ActionResult MyAction() { YourModel model = new YourModel(); model.WidgetTypes = Business.MySession.Current.WidgetTypes .ToSelectList(d => d.TypeName, d => d.WidgetTypeID.ToString(), " - Select - "); return View(model); }
Then, in your opinion, just do:
@Html.DropDownListFor(model => model.WidgetTypeID, Model.WidgetTypes)
source share