2

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

1 Answer 1

4

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" })
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you so much!!! What documentation did you refer to? in other words - what can I reference to know how to program with the TBS?
The different html helpers are documented in the MSDN. To learn how to program with ASP.NET and the razor syntax in general I'd recommend to read through the tutorials here
Thanks!! and for the @html.DropDownList("viewbagItems","Select an Item"); How would you incorporate the TBS style into it? Many thanks :)
Almost every helper also has a HelperFor-method, just look for a method overload accepting a "htmlAttributes" parameter. That would be the right place to define custom styles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.