0

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.

Peter
  • 203
  • 2
  • 4
  • 13
  • 1
    Please refer [this][1] question, it's similar to your question. [1]: http://stackoverflow.com/questions/22386710/asp-net-mvc-generate-dropdownlist-using-uihint-attribute – Krushnakant Ladani Aug 03 '14 at 19:45
  • That was a nice one except that I couldn't understand what he meant in `ItemType` in the controller. I guess every other thing I understand. – Peter Aug 03 '14 at 20:06
  • ok now. I got it right. Thanks – Peter Aug 03 '14 at 20:38

0 Answers0