How to create a readonly text using html helper in asp.net mvc?

后端 未结 6 1956
陌清茗
陌清茗 2020-12-15 17:54

I want to disable a textbox in the view. So I use following code:

<%= Html.TextBox(\"ID\", Model.ID, new { readonly=\"true\" })%>

or

6条回答
  •  星月不相逢
    2020-12-15 18:08

    Try

    <%= Html.TextBox("ID", Model.ID, null, new { @readonly="true" })%>
    

    instead of

    <%= Html.TextBox("ID", Model.ID, new { @readonly="true" })%>
    

    If you check the documentation, you can see that the third parameter is not htmlAttributes, as you probably expected.

    You need to use the overload with four parameters.

提交回复
热议问题