Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How Can i make the EditorFor input disabled

i have tried using the below which doesn't work

@Html.EditorFor(model => model.TaskName, new { disabled = "disabled", @readonly = "readonly" })
Posted
Updated 25-Jul-22 23:32pm

The EditorFor html helper does not have overloads that take HTML attributes. In this case, you need to use something more specific like TextBoxFor:

C#
<div class="editor-field">
    @Html.TextBoxFor(model => model.userName, new 
        { disabled = "disabled", @readonly = "readonly" })
</div>

Hope this helps
 
Share this answer
 
Comments
Adam Jones 25-Sep-13 10:28am    
For some reason the DisplayFor & TextBoxFor do not allow post back
Its posting back as null
Jameel VM 25-Sep-13 10:51am    
i think that is because of some other problem.Please post that problem as separate thread.
Adam Jones 25-Sep-13 11:01am    
The disable attribute does not return a value read only works OK though

Thx
The disable attribute does not return a value read only works OK though
 
Share this answer
 
@Html.EditorFor(model => model.Issued_CreatedBy, new {htmlAttributes = new { disabled = true, @class = "form-control ", @Value = Session["Username"] } })
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900