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

Shyju picture Shyju · Jan 6, 2012 · Viewed 236.3k times · Source

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)

Answer

user596075 picture user596075 · Jan 6, 2012
@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?