model-view-controllerviewwidthdropdownlistforhtml.textboxfor

Can I make DropDownListFor width the same like TextBoxFor width with Bootstrap class?


I have NewCustomer View:

        <table class="table">
            <tr>
                <td class="text-right">
                    @Html.LabelFor(model => model.Customer.GenderId)
                </td>
                <td>
                    @Html.DropDownListFor(model => model.Customer.GenderId,new SelectList(Model.Genders,"Id", "GenderType"),"-=Select Title=-")
                </td>
            </tr>
            <tr>
                <td class="text-right">
                    @Html.LabelFor(model => model.Customer.Name)
                </td>
                <td>
                    @Html.TextBoxFor(model => model.Customer.Name)
                </td>
            </tr>

        </table>

Can I align the width dropdownlist and textbox with boostrap class ?

DropDownList is too narrow


Solution

  • I changed code:

        <div class="form-horizontal">
    
            <div class="form-group">
                @Html.LabelFor(model => model.Customer.GenderId, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">   
    
                    @Html.DropDownListFor(model => model.Customer.GenderId, new SelectList(Model.Genders, "Id", "GenderType"), "Select Title", new { @class = "form-control " })
                    @Html.ValidationMessageFor(model => model.Customer.GenderId, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Customer.Name, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Customer.Name, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Customer.Name, "", new { @class = "text-danger" })
                </div>
            </div>
    </div>