0

Hi I want to make my textbox's width longer.

The view that is generated, uses @Html.EditorFor which I noticed I can't modify nor I can add css style to it.

So I checked, TextAreFor and it works but it creates a scrollbar since it is a textarea

e.g.

@Html.TextAreaFor(model => model.Name, new { cols=50, @rows=1 })

How would I remove the scrollbar? so it looks like it is a textbox? or is there another way to generate a textbox with a custom width?

Thanks,

3 Answers 3

1

You can use TextBoxFor HTML Helper method for generating a input element with a custom class like this

  @Html.TextBoxFor(m => m.Name, new { @class="yourCustomClass" })

and now you can define your custom styles in this class

.yourCustomClass
{
  width:340px;
}
Sign up to request clarification or add additional context in comments.

4 Comments

Your code is fine, but my question is something else, when placing your code or my code it still creates a scrollbar, i want it to not show the scrollbar, so it would look like a textbox.
then it is some thing with the CSS. Post your css.probably the HTML markup and relevant css in jsfiddle.net
I don't have any css. I am using exact code you posted. when outputting on the UI, the textbox control shows with multiple lines and with a scrollbar. Thx
use firebug to see what css being applied. IT is clearly a css issue.Can you post your css and html in a jsfiddle ?
0

Use a CSS class with the following statement:

overflow:hidden

Comments

0

Maybe

@Html.TextBoxFor(m => m.Name, new { @style="width:150px; height:50px; overflow:hidden;" })

Comments

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.