Instead of disabling the drop-down list, why not replace it with the selected option ... if you are doing this for a lot of things, you should think about having read-only access and an editable view ...
<% if (Model.IsReadOnly) { %> <%= Model.MyModel.MyType %> <% } else { %> <%= Html.DropDownListFor(model => model.MyModel.MyType, EnumHelper.GetSelectList< MyType >(),new { @class = "someclass", someattrt = "someattrt"})%> <% } %>
And just as an aside, you only need to escape the attribute name with "@" if it is a reserved word, such as "class".
Update
Good. I have an answer for you - but on the condition that you read this before doing it.
MVC is all about sharing issues. Inclusion of logic in a controller, which is especially relevant to presentation, is an abuse of MVC. Please do not do this. Everything that is characteristic of the presentation, such as HTML, attributes, layout - none of this should be present in "controllerville". The controller should not change because you want to change something in the view.
It is very important that you understand what MVC is trying to achieve, and that the following example breaks the entire template and puts the presentation material in a completely wrong place in your application.
The correct fix will be to have a โreadโ and โeditโ view โ or put any conditional logic in the view. But here is a way to do what you want. :(
Add this property to the model.
public IDictionary<string, object> Attributes { get; set; }
In the controller you can conditionally set the attributes:
model.Attributes = new Dictionary<string, object>(); model.Attributes.Add(@"class", "test"); if (isDisabled) { model.Attributes.Add("disabled", "true"); }
Use attributes in your view:
<%= Html.TextBoxFor(model => model.SomeValue, Model.Attributes)%>