I am having a problem with DropDown using EditorTemplates
. Currently I have my it all like this:
view model
[Required]
[Display(Name = "Answer")]
public string Answer { get; set; }
[UIHint("DropDown")]
public IEnumerable<UserRoles> Roles { get; set; }
Controller:
[HttpGet]
public ActionResult Users() {
var uroles = (from mm in db.roles
orderby mm.RoleName
select mm).ToList();
ViewBag.Uroles = new SelectList(uroles, "RoleId", "RoleName");
ViewBag.Content = UserServices.LoginUser().ToList();
return View("Users");
}
and my view like this
@model Models.RegisterModel
<a href="#" id="createform">Create New</a>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.EditorForModel()
@Html.DropDownList("uroles", (SelectList) ViewBag.Uroles)
<input type="submit" value="Create User" />
}
The chasllenge is I want to have my DropDownList
in EditorTemplates
folder like I have that of the String.cshtml:
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue)
How do you think I can achieve this? I hate to type-out all HTML tags in every form forms (I guess I'm being lazy). Thanks.