tags:

views:

54

answers:

1

I'm trying to produce a dropdownlist for GetAllRoles using the role provider.

I can produce the drop down in a controller using ViewData but I would like to use a View Model to produce the dropdown, but I'm unsure of the best way to create the list using a View Model?

public ActionResult GetAllRoles()
{
   ViewData["Roles"] = new SelectList(Roles.GetAllRoles());
   return View(); 
}
+1  A: 
Raj Kaimal
I would like to add the GetAllRoles in my model not in the controller.public string GetAllRoles(){ var AllRoles = new SelectList(Roles.GetAllRoles()); return AllRoles;}[Required][DisplayName("AllRoles")]public String AllRoles { get; set; }
Jemes
Thanks Raj that's working great, I think I was just using a string rather than a SelectList. When I'm now creating my strongly typed View it doesn't seem to create the HTML.Dropdown code. Would I just add this myself? I would have liked to the use Html.EditorFor().
Jemes
Would I just add this myself? Unfortunately, yes.
Raj Kaimal