I have the following inside my asp.net mvc web application :-
我的asp.net mvc web应用程序中有以下内容:-
<div><span class="f">Data Center Name</span> @Html.EditorFor(model => model.Switch.TMSRack.DataCenter.Name, new { disabled = "disabled" })</div>
but the field will not be disabled ,, can anyone adivce please? THanks
但是这个领域不会被禁用,谁能说再见吗?谢谢
5 个解决方案
#1
48
@Html.EditorFor()
does not have an overload to support htmlAttributes. You could try @Html.TextBoxFor()
@Html.EditorFor()没有重载来支持htmlAttributes。你可以试试@Html.TextBoxFor()
@Html.TextBoxFor(model => model.propertyName, new {disabled= "disabled" })
If you are using system key words such as class
in htmlAttributes please add @
before the attribute name.
如果您正在使用系统关键字,如htmlAttributes中的类,请在属性名之前添加@。
Ex:
例:
@Html.TextBoxFor(model => model.propertyName, new {@class = "disabledClass" })
#2
15
Using MVC 5, @Html.EditorFor()
supports htmlAttributes
使用MVC 5, @Html.EditorFor()支持htmlAttributes
@Html.EditorFor(model => model.x, new { htmlAttributes = new { @class = "form-control", @disabled = "disabled" } })
The above example shows how you can add a class and also the disabled attribute
上面的示例展示了如何添加类和禁用属性
#3
7
Another alternative: surround the EditorFor with a div or a span with a certain id, and then use a bit of jquery/js:
另一种选择:使用一个div或一个具有特定id的span包围编辑器,然后使用一些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>
#4
1
You can also use EditorFor()
eg:- @Html.EditorFor(model => model.Nama, new { htmlAttributes = new { @class = "form-control", @disabled ="true" } })
您还可以使用EditorFor() eg:- @Html。EditorFor(模型= >模型。Nama, new {htmlAttributes = new {@class =" form-control", @disabled ="true"})
#5
0
If you lose information when you accept the Edit-changes ... You could try
如果您在接受编辑更改时丢失了信息……你可以试试
<h3>@Model.x</h3>
@Html.HiddenFor(model => model.x, new { htmlAttributes = new { @class = "form-control" } })
#1
48
@Html.EditorFor()
does not have an overload to support htmlAttributes. You could try @Html.TextBoxFor()
@Html.EditorFor()没有重载来支持htmlAttributes。你可以试试@Html.TextBoxFor()
@Html.TextBoxFor(model => model.propertyName, new {disabled= "disabled" })
If you are using system key words such as class
in htmlAttributes please add @
before the attribute name.
如果您正在使用系统关键字,如htmlAttributes中的类,请在属性名之前添加@。
Ex:
例:
@Html.TextBoxFor(model => model.propertyName, new {@class = "disabledClass" })
#2
15
Using MVC 5, @Html.EditorFor()
supports htmlAttributes
使用MVC 5, @Html.EditorFor()支持htmlAttributes
@Html.EditorFor(model => model.x, new { htmlAttributes = new { @class = "form-control", @disabled = "disabled" } })
The above example shows how you can add a class and also the disabled attribute
上面的示例展示了如何添加类和禁用属性
#3
7
Another alternative: surround the EditorFor with a div or a span with a certain id, and then use a bit of jquery/js:
另一种选择:使用一个div或一个具有特定id的span包围编辑器,然后使用一些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>
#4
1
You can also use EditorFor()
eg:- @Html.EditorFor(model => model.Nama, new { htmlAttributes = new { @class = "form-control", @disabled ="true" } })
您还可以使用EditorFor() eg:- @Html。EditorFor(模型= >模型。Nama, new {htmlAttributes = new {@class =" form-control", @disabled ="true"})
#5
0
If you lose information when you accept the Edit-changes ... You could try
如果您在接受编辑更改时丢失了信息……你可以试试
<h3>@Model.x</h3>
@Html.HiddenFor(model => model.x, new { htmlAttributes = new { @class = "form-control" } })