Can I set text box to readonly when using Html.TextBoxFor?

后端 未结 15 1528
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 18:07

I have the following tag with a Html.TextBoxFor expression and I want the contents to be read only, is this possible?

<%= Html.TextBoxFor(m => Model.E         


        
相关标签:
15条回答
  • 2020-12-08 18:59

    Use the following:

     @Html.TextBoxFor(m => m.Whatever, new {@readonly = "readonly"})
    

    If you want to assign a class to it you could do it the same way , by adding the @class = "" property. Hope this helps :)

    0 讨论(0)
  • 2020-12-08 19:01

    An other possibility :

    <%= Html.TextBoxFor(model => Model.SomeFieldName, new Dictionary<string, object>(){{"disabled", "true"}}) %>
    
    0 讨论(0)
  • 2020-12-08 19:01

    Using the example of @Hunter, in the new { .. } part, add readonly = true, I think that will work.

    0 讨论(0)
提交回复
热议问题