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

后端 未结 15 1526
爱一瞬间的悲伤
爱一瞬间的悲伤 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:43

    In fact the answer of Brain Mains is almost correct:

    @Html.TextBoxFor(model => model.RIF, new { value = @Model.RIF, @readonly = true })
    
    0 讨论(0)
  • 2020-12-08 18:45

    You can also disabled TextBoxFor

    @Html.TextBoxFor(x=>x.day, null, new { @class = "form-control success" ,@disabled="disabled" })
    
    0 讨论(0)
  • 2020-12-08 18:46

    The following snippet worked for me.

    @Html.TextBoxFor(m => m.Crown, new { id = "", @style = "padding-left:5px", @readonly = "true" }) 
    
    0 讨论(0)
  • 2020-12-08 18:47

    This work for me...

    @Html.TextBoxFor(model => model.RIF, new { value = @Model.RIF, @readonly = "readonly" })
    
    0 讨论(0)
  • 2020-12-08 18:47

    By setting readonly attribute to either true or false is not going to work in most browsers, I have done it as below, when the mode of the page is "reload", I've not included "readonly" attribute.

    @if(Model.Mode.Equals("edit")){
    @Html.TextAreaFor(model => Model.Content.Data, new { id = "modEditor", @readonly = moduleEditModel.Content.ReadOnly, @style = "width:99%; height:360px;" })
    }
    @if (Model.Mode.Equals("reload")){
    @Html.TextAreaFor(model => Model.Content.Data, new { id = "modEditor", @style = "width:99%; height:360px;" })}
    
    0 讨论(0)
  • 2020-12-08 18:48
    <%= Html.TextBoxFor(m => Model.Events.Subscribed[i].Action, new { @readonly = true })%>
    
    0 讨论(0)
提交回复
热议问题