I have problem in my code. I\'m using the registration form which comes with MVC5 , I added a field \"Role\" as a Dropdownlist to assign a role to the user while creating a
Personally I would create the select list in your controller and pass it to the model, writing something like
var RolesList = new List
{
new SelectListItem { Value = string.Empty, Text = "Please select a Role..." }
};
RolesList.AddRange(roles.Select(t => new SelectListItem
{
Text = t.role,
Value = t.Id.ToString()
}));`
and then add this to your model, in your model you can then use
@Html.DropDownListFor(m => m.Role, Model.RoleList, new { @class = "form-control" })
This method/syntax works for me I am not sure if It is 'best practice' though