How to Set a Larger Size for a Textboxfor

Asked

Viewed 2,872 times

2

I’m using the class form-control of Boostrap, and I’d like to have a Textboxfor with a bigger size, how can I do this ?

<div class="form-horizontal">
<div class="row">
    <div class="form-group">
        @Html.Label("Titulo do E-mail:", new { @class = "col-sm-4 control-label" })
        <div class="col-md-6">
            @Html.TextBoxFor(model => model.strTituloEmail, new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.strTituloEmail)
        </div>
    </div>
</div>

  • Diego, try to do this: @Html.Textboxfor(model => model.strTituloEmail, new { @class = "form-control input-lg" }). This way bootstrap recognizes the class to be used and applies to the element. This is what you wanted ?

3 answers

3


You can use Htmlattributes from the Asp.net MVC Htmlhelper itself.

You can just put a style, setting the width to the desired size:

@Html.TextBoxFor(model => model.strTituloEmail, new { @class = "form-control form-control-custom", @style="width:1000px;"})

Result in HTML:

<input class="form-control form-control-custom" id="strTituloEmail" name="strTituloEmail" style="width:1000px;" type="text" value="">

Or creating a class customized to your desired style, for example:

<style>
    .form-control-custom {
        width: 1000px;
    }
</style>

And then use your class customized addition to class bootstrap. (Just don’t forget that your style should always be loaded later than bootstrap, to overwrite it)

@Html.TextBoxFor(model => model.strTituloEmail, new { @class = "form-control form-control-custom"})

Result in HTML:

<input class="form-control form-control-custom" id="strTituloEmail" name="strTituloEmail" type="text" value="">

Use the CSS hierarchy to your advantage, remember what the acronym means CSS (Cascading Style Sheets), use the C.

2

You can use the Htmlattribute, and use html tags inside your textbox.

In your specific case it would look like this:

  @Html.TextBoxFor(model => model.strTituloEmail, new { @class = "form-control", style = "width:250px; height: 30px;"})

This way you can change the height and width of yourself TextBox changing the values that are in the width and in the height.

You can check the usage in this example: dotNetFiddle

1

Just add the class and size in Htmlattributes:

Html.TextBoxFor(model => model.TeuCampo, new { @class = "form-control", style="width:50px;"}
  • I tried to do it the way you suggested, but it still didn’t work. Description: Error when parsing a resource needed to fulfill this request. Examine the specific details of the parse error and modify the source file appropriately. Parser Error Message: "class" is a reserved word and cannot be used in implicit Expressions. An Explicit Expression ("@()") must be used.

  • use width: 50px ! Important; or create a css class, like the @Fernando response, also use ! Important after passing the size px

  • @Rod if you maintain the hierarchy of your styles and import your style, or declare it after importing the bootstrap, the !important is not necessary.

  • @Diegodias, only now I managed to come here. I see that you have to answer, good :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.