1

I know this is an old question that has already been answered on StackOverFlow. However, none of those answers is working here. I can't apply CSS on any of my html helpers.

My HTML:

@Html.TextBox("Origin", new { @class = "MyInputClass" }) 

My CSS:

 .MyInputClass
{
 width:300px;
} 

Instead of getting a 300px width textbox, I get a textbox with the text: { class = MyInputClass }

if I try instead:

@Html.TextBox("Origin", "123", new { @class = "MyInputClass" }) 

Then I'll get a textbox with the text "123" but with the default width...

4
  • Where did you define css class? Commented Feb 25, 2014 at 11:37
  • Site.Css using <link rel="stylesheet" type="text/css" href="~/content/Site.css"> Commented Feb 25, 2014 at 11:41
  • 1
    Your second example should work. Are you sure another class is not overriding the width set by .MyInputClass? Commented Feb 26, 2014 at 2:39
  • Thank you HTX9! That was it! Insert the same sentence as an answer and I'll accept it! Many thks! Commented Feb 26, 2014 at 9:24

1 Answer 1

3

Not sure whats wrong, because I tried both of your examples and they worked as expected.

Got:

<input class="MyInputClass" id="Origin" name="Origin" type="text" value="">

and

<input class="MyInputClass" id="Origin" name="Origin" type="text" value="123">

Is CSS linked correctly?

EDIT: Maybe you changed something, but now first example will make text box with "{ class = MyInputClass }" in it. Add empty string parameter in the middle, to make an empty text box:

@Html.TextBox("Origin", "", new { @class = "MyInputClass" }) 
Sign up to request clarification or add additional context in comments.

1 Comment

Hi berzinsu, yes, it's perfectly linked. It's working on other parts of the html code.

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.