Question

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...

Was it helpful?

Solution

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" }) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top