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

后端 未结 6 1949
陌清茗
陌清茗 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条回答
  •  萌比男神i
    2020-12-15 18:11

    Try

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

    I'm not sure you have to use the overload with 4 parameters. You should be able to use the one with 3, but you need to append @ to the readonly since readonly is a keyword in C#. And setting @readonly to readonly is XHTML compliant.

提交回复
热议问题