我有以下我的asp.net MVC Web应用程序中: -如何使@ Html.EditorFor残疾人
<div><span class="f">Data Center Name</span> @Html.EditorFor(model => model.Switch.TMSRack.DataCenter.Name, new { disabled = "disabled" })</div>
,但该领域不会被禁用,,谁能书于好吗? THanks
我有以下我的asp.net MVC Web应用程序中: -如何使@ Html.EditorFor残疾人
<div><span class="f">Data Center Name</span> @Html.EditorFor(model => model.Switch.TMSRack.DataCenter.Name, new { disabled = "disabled" })</div>
,但该领域不会被禁用,,谁能书于好吗? THanks
@Html.EditorFor()
没有重载支持htmlAttributes。如果使用的是系统的关键字,如htmlAttributes class
请属性名称前面加@
你可以尝试@Html.TextBoxFor()
@Html.TextBoxFor(model => model.propertyName, new {disabled= "disabled" })
。
例:
@Html.TextBoxFor(model => model.propertyName, new {@class = "disabledClass" })
与两个c lass和TextBoxFor: @ Html.TextBoxFor(model => model.Doctor.Label1,new {@class =“form-control”,disabled =“disabled”}) – MuniR
另一种替代方法:包围EditorFor与一个div或具有一定ID的跨度,然后用一个比特的jquery/JS的:
<span id="editors">
@Html.EditorFor(x => x.ViewModelProperty)
</span>
<!-- Disable above editors. EditorFor doesn't allow html attributes unfortunately. -->
<script type="text/javascript">
$(function() { $('#editors :input').attr("disabled", true); });
</script>
使用MVC 5 ,@Html.EditorFor()
支持htmlAttributes
@Html.EditorFor(model => model.x, new { htmlAttributes = new { @class = "form-control", @disabled = "disabled" } })
上面的例子说明如何添加一个类人所以残疾人属性
如果您在接受编辑,更改会丢失信息... 你可以尝试
<h3>@Model.x</h3>
@Html.HiddenFor(model => model.x, new { htmlAttributes = new { @class = "form-control" } })
您还可以使用EditorFor()
如: - @Html.EditorFor(model => model.Nama, new { htmlAttributes = new { @class = "form-control", @disabled ="true" } })
从MVC 5.1起'@ Html.EditorFor(model => model.Property,new {htmlAttributes = new {@ disabled =“disabled”}})' –
如果您使用的是asp核心,我在这里解释了一个解决方案: https:// stackoverflow。 com/a/44639822/6339469 – HamedH