0

I have been looking around. I have a Model with an Enum, almost like a Helper to select from witch Column to search:

namespace Test.Models
{
    public class ViewEnums
    {
        public SearchParameter? searchParameter { get; set; }
    }

public enum SearchParameter
{
    A,
    B,
    C,
    D
}
}

And a View :

    @using Test.Models;
    (...)
    Find :@Html.EnumDropDownListFor("SearchParameter",SearchParameter)

How can I get this EnumDropDownList to work? If it was in the model which was passed I could get it to work. But the Enum is in another Model. Can anyone help me?

tereško
  • 58,060
  • 25
  • 98
  • 150
Nochoi
  • 1
  • Create a view model which includes all the models/properties you need –  Aug 30 '14 at 13:11
  • Tried to put the enum in the Main model and do: @Html.EnumDropDownListFor(model => model.SearchParameter) but with no luck. – Nochoi Aug 30 '14 at 14:13
  • Got a part working using `IEnumerable listSearchParameters = Enum.GetValues(typeof(SearchParameter)).Cast().Select(v => new SelectListItem { Text = v.ToString() }); ; @Html.DropDownList("SearchParameters", new SelectList(listSearchParameters, "Text"), "SearchParameter")` Now I need to change the entry of my controller (SearchParameter) to String. Pitty I wanted to use the Enum type... – Nochoi Aug 30 '14 at 15:28
  • Are you using the `EnumDropDownListFor` method in MVC 5, or is this a custom helper? `@Html.EnumDropDownListFor(m => m.SearchParameter)` works. –  Aug 30 '14 at 23:29
  • I am using the EnumDropDownListFor method in MVC5, not a custom one. – Nochoi Sep 05 '14 at 09:06
  • possible duplicate of [How do you create a dropdownlist from an enum in ASP.NET MVC?](http://stackoverflow.com/questions/388483/how-do-you-create-a-dropdownlist-from-an-enum-in-asp-net-mvc) – Robert MacLean Feb 21 '15 at 20:35

0 Answers0