-2

I want to add custom class to Asp.net Razor MVC control @Html.DropDownListFor

I have following code

@Html.DropDownListFor(model => model.is_admin, new SelectList(
            new List<Object>{ 
                new { value = "true" , text = "Admin"  },  
                new { value = "false" , text = "User"  },                                               
             },                    
             "value",
             "text",
              "false" ))

How can this same control be implemented in Asp.net MVC 5

1
  • @Html.DropDownListFor(model => model.is_admin, new SelectList(....), new { @class = "yourClassName" ")
    – user3559349
    Commented Feb 2, 2016 at 6:33

1 Answer 1

1

Add a third parameter called htmlAttributes like following.

@Html.DropDownListFor(model => model.is_admin,
       new SelectList(
           new List<Object>{
               new { value = "true" , text = "Admin"  },
               new { value = "false" , text = "User"  },

            }, "value", "text", "false"),
       new { @class = "your_class_name" });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.