Click here to Skip to main content
15,924,196 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a html.Dropdownlistfor a set of enums that I loaded into the viewbag then selected the current selected item? My current code does not work.

Controller:

//This does appear to load the ViewBag with the correct values.

ViewBag.AppRoleList = new SelectList(Enum.GetValues(typeof(APPRole)));

// View

Html.DropDownListFor (@Model.ROLE, ViewBag.AppRoleList as SelectList)

Here I get an Arguemt type cannot be inferred from usage type of message.

Note my model only has four porperties:

ID
ROLEID
ROLE
ACTIVE

And the model can not be changed.



Please help.


Steve Holdorf
Posted
Updated 9-Jul-14 7:20am
v2

1 solution

Hi,

Refer to this link :http://stackoverflow.com/questions/388483/how-do-you-create-a-dropdownlist-from-an-enum-in-asp-net-mvc[^]

Read the second solution if you are using MVC 5 or >
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900