CSS样式{Display:none}在htmlattribute中不起作用

时间:2016-11-24 08:16:14

标签: javascript jquery html asp.net-mvc

我在display: none调用中使用CSS样式TextBoxFor,但它无效。

<img id="Img" src="~/abc/def.jpg" style="height: 120px; max-width: 100%; width: 280px;" class="img-responsive" />
@Html.TextBoxFor(m => m.dP,  new { htmlAttributes = new { @class = "form-control has-feedback-left file btntag", @onchange = "openFile(event)", @style="display: none;", @type="file", placeholder = "Upload Display Picture" } })
@Html.ValidationMessageFor(model => model.dP, "", new { @class = "text-danger" })

2 个答案:

答案 0 :(得分:0)

<img id="Img" src="~/abc/def.jpg" style="height: 120px; max-width: 100%; width: 280px;" class="img-responsive" />
@Html.TextBoxFor(m => m.dP,  new { @class = "form-control has-feedback-left file btntag", onchange = "openFile(event)", style="display: none;", @type="file", placeholder = "Upload Display Picture" } )
@Html.ValidationMessageFor(model => model.dP, "", new { @class = "text-danger" })

以上是为助手定义html属性的正确方法。 (删除额外的“htmlAttributes = new”部分。)

答案 1 :(得分:0)

将TextBoxFor语法更改为以下内容。

@Html.TextBoxFor(m => m.dP, new { @class = "form-control has-feedback-left file btntag", onchange = "openFile(event)", style="display: none;", @type="file", placeholder = "Upload Display Picture" })

classtype需要前缀@,因为这两个是C#关键字。因此,要使用@解决歧义前缀,使其成为@class@type

的HTML属性

同时删除htmlAttributes部分。基本语法如下。

@Html.TextBoxFor(m => m.Email, new { ... })  // ... is your HTML attributes