Asp.net-Mvc-3

如何將 TextBoxFor 設置為預設隱藏

  • May 21, 2021

我在 MVC3 中有一個視圖,其中 TextBoxFor 綁定到我的模型,如下所示:

<%=Html.TextBoxFor(m => m.SomeProperty, new { @readonly = "readonly" }) %>

我怎樣才能將其更改為具有 style=“display: none;” 的文本框 預設情況下?

不確定預設情況下您的意思,但您可以添加樣式屬性:

<%= Html.TextBoxFor(m => m.SomeProperty, new { style = "display: none;" }) %>

或者:

<%= Html.TextBoxFor(m => m.SomeProperty, new { @class = "hidden" }) %>

在你的 CSS 文件中:

.hidden {
   display: none;
}
Html.TextBoxFor(m => m.SomeProperty, new { @readonly = "readonly", @hidden="true"})

引用自:https://stackoverflow.com/questions/8800446