Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditorTemplate for DropDownList

Tags:

I've created an EditorTemplate for string fields that implements bootstrap as follows:

@using MyProject
@model object
<div class="form-group">
    @Html.LabelFor(m => m, new { @class = "col-md-3 control-label" })
    <div class="col-md-9">
        @Html.TextBox(
            "",
            ViewData.TemplateInfo.FormattedModelValue,
            htmlAttributes)
        @Html.ValidationMessageFor(m => m, null, new { @class = "help-block" })
    </div>
</div>

And I can call this simply like this:

@Html.EditorFor(model => model.FirstName,"BootstrapString")

My Question: How would I do this for a DropDownList so that I can merely call @Html.EditorFor as follows:

@Html.EditorFor(model => model.CategoryId,new SelectList(ViewBag.Categories, "ID", "CategoryName"))

So it's basically a Generic DropDownList with Twitter Bootstrap styling.