user2911759 user2911759 - 1 month ago 6
CSS Question

How to override CSS for TextBoxFor field?

Have the following class in Site.css:

input[type="textbox"].TextBoxAsLabel {
background:#f2f3f3 !IMPORTANT;
}


want to override default background for TextBoxFor field in Edit.cshtml

@Html.TextBoxFor(model => model.ClientNumber, new {@readonly = "readonly", @class = "TextBoxAsLabel"})


and it still uses default white background. What should I change?

Answer

I realized that problem was in location of CSS file. Now code in separate styles.CSS is:

  .message-label {
    background-color: #f2f3f3;
  }

Styles.css is referenced in _Layout.cshtml:

 <link href="@Url.Content("~/Content/styles.css")" rel="stylesheet" type="text/css" />

and in CHTML:

 @Html.TextBoxFor(model => model.ClientNumber, new {@readonly = "readonly", @class ="message-label"})

and it works!

Comments