【问题标题】:@Html.DisplayFor() will not show client side?@Html.DisplayFor() 不会显示客户端?
【发布时间】:2013-06-26 06:15:46
【问题描述】:

我正在 MVC 4 中开发,我想要一个只读文本框。我决定使用@Html.DisplayFor 但我无法让它显示在客户端?

<div class="editor-label">
    @Html.LabelFor(model => model.GoodsModel.SerialNumber) <label id ="VGoodsSerialNumber" style="color: #FF0000;"/>
</div>
<div class="editor-field">
    @Html.DisplayFor(model => model.GoodsModel.SerialNumber)
    @*@Html.EditorFor(model => model.GoodsModel.SerialNumber, new { disabled = "disabled", @readonly = "readonly" })*@
</div>

那我跑的时候找不到?

【问题讨论】:

  • 谢谢,仍然无法将 EditorFor 呈现为只读。
  • 你有模型类型的模板吗?

标签: asp.net-mvc displayfor


【解决方案1】:

Html.EditorFor 没有 htmlAttributes 参数。如果要传递html属性,则需要使用Html.TextBoxFor:

@Html.TextBoxFor(model => model.GoodsModel.SerialNumber, new { @readonly = "readonly" })

另外,使用禁用或只读。当输入被禁用时,它的值在提交表单时不会被发送到服务器。只读输入仍将被发布,但用户无法更改其值。

【讨论】:

    猜你喜欢
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 2019-10-05
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多