How can I apply styling to asp.net mvc @Html.TextboxFor?

An overload of the TextBoxFor method allows you to pass an object for the HTML attributes.

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I want to change the background of the textbox. This is my code: @Html. TextBoxFor(p => p.

Publishers0. Pub_name) What more do I need to write in TextBoxFor to change the background? Thanks in advance :) c# asp.net" rel="nofollow">asp.net asp.net" rel="nofollow">asp.net-mvc mvc link|improve this question edited Nov 23 '11 at 11:59Peter Kelly2,936817 asked Jul 31 '11 at 1:58Anthony3,83111670 84% accept rate.

An overload of the TextBoxFor method allows you to pass an object for the HTML attributes. @Html. TextBoxFor(p => p.

Publishers0. Pub_name, new { Class="YourBackgroundClass" }) Then you can have a CSS rule such as: . YourBackgroundClass { background:#cccccc; } If you want to apply a style directly you can do: @Html.

TextBoxFor(p => p. Publishers0. Pub_name, new { Style="background:#cccccc;" }).

Thanks and what if I do not want to use class. Instead directly specify some attribute? I tried and this doesn't work: ` @Html.

TextBoxFor(p => p. Publishers0. Pub_name, new { foreground = "red" })` – Anthony Jul 31 '11 at 2:03 Also using your example doesn't work.

I get error because class is reserved word. – Anthony Jul 31 '11 at 2:06 2 @Anthony: I fixed the sample, it should've been @class because indeed class is a reserved keyword. – Dan Abramov Jul 31 '11 at 2:12 2 The "foreground" property will not work as it is not an HTML attribute, you have to disconnect your mind from the "webforms" way of thinking, these attributes are pure HTML.

If you didn't want to use a class you could use an inline style using the "Style" attribute. – rkaregaran Jul 31 '11 at 2:12 Also, you should use CSS classes to specify styling. But if you have reasons to do it inline (I highly doubt so), use style attribute: new { style = "color: red" }.. – Dan Abramov Jul 31 '11 at 2:13.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions