我在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" })
答案 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" })
仅class
和type
需要前缀@
,因为这两个是C#关键字。因此,要使用@
解决歧义前缀,使其成为@class
和@type
同时删除htmlAttributes
部分。基本语法如下。
@Html.TextBoxFor(m => m.Email, new { ... }) // ... is your HTML attributes