asp.net-mvcasp.net-mvc-2

Check for the option label string


I'm using the option Label string for my Html.DropDownList but my datasource is a SelectList. How I would check for the option label back on the server? The backing type for the variable is an EnumType. I inspected the value and it says 0 but it won't let me check for 0.


Solution

  • How about casting the value back to the enum type on the server:

    [HttpPost]
    public ActionResult Index(int selectedValue)
    {
        MyEnum label = (MyEnum)selectedValue;
        ...
    }