Gman16
Gman16

Reputation: 183

Formatting Textboxes in MVC4 Twitter Bootstrap C#

I have tried many of the tutorials implementing the Twitter Bootstrap into MVC4 with VS2012 whilst still trying to keep the authentication code (i.e. using Internet Application).

My Issue is that when I use the scaffolding to do all my CRUD pages of the model I define, it does not use the twitter bootstrap formatting.

Here is the generated code:

    <div class="editor-label">
        @Html.LabelFor(model => model.lastName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.lastName)
        @Html.ValidationMessageFor(model => model.lastName)

And the output is a norrmal editbox and NOT the nice twitter box with blue outline, etc...

So I tried:

        @Html.TextBox("Test","",new {@class="form-control"})

and that rendered perfectly... so then I tried:

        @Html.EditorFor(model => model.lastName, new { @class = "form-control" })

And it subsequently did not work.

Please could someone suggest how I can resolve this issue or alternatively where can I download a pre-made template of Twitter-bootstrap integrated with MVC4 so I can simply just start programming.

I can provide any other code required.

Thanks in advance

Upvotes: 2

Views: 3384

Answers (1)

sky
sky

Reputation: 441

That is because the method you are using

@Html.EditorFor( Expression<Func<TModel, TValue>> expression, object additionalViewData )

does not expect "htmlAttributes" as does the @Html.Textbox-Helper.

You could use

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

Upvotes: 4

Related Questions