Search code examples
c#asp.net-mvc-3razorhtml-helperreadonly-attribute

How to create a readonly textbox in ASP.NET MVC3 Razor


How do I create a readonly textbox in ASP.NET MVC3 with the Razor view engine?

Is there an HTMLHelper method available to do that?

Something like the following?

@Html.ReadOnlyTextBoxFor(m => m.userCode)

Solution

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

    You are welcome to make an HTML Helper for this, but this is simply just an HTML attribute like any other. Would you make an HTML Helper for a text box that has other attributes?