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

前端 未结 3 931
北海茫月
北海茫月 2020-12-28 13:30

I want to change the background of the textbox. This is my code:

@Html.TextBoxFor(p => p.Publishers[0].pub_name)

What more do I need to

3条回答
  •  青春惊慌失措
    2020-12-28 14:09

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

    @Html.TextBoxFor(p => p.Publishers[0].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.Publishers[0].pub_name, new { Style="background:#cccccc;" })
    

提交回复
热议问题