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

后端 未结 6 1942
陌清茗
陌清茗 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:05

    If you are not forced to show a readonly textbox in your web page, consider using the @Html.DisplayFor helper: your output will be readonly (actually it will be just a text in a div) and will be part of the Model when the engine will model bind on submit.

提交回复
热议问题