user2169717 user2169717 - 1 year ago 84
C# Question

making text field viewable but not editable

I am using the code bellow to allow users to add view the user name as this name is given by the active directory i would like them to see the filed with name added but not able to edit the data any ideas how i would be able to achieve this

@Html.EditorFor(model => model.UserName)

I have also tried the folowwing two methods which do no work both with or with @ anslo with the statment true

@Html.EditorFor(model => model.UserName, new { @disabled ="disabled"})
@Html.EditorFor(model => model.UserName, new { @readonly = "readonly" })

Answer Source

Go for go @Html.TextBoxFor extension which you can pass an overload:

@Html.TextBoxFor(model => model.UserName, new { @readonly = true }) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download