ReadOnly Attribute in MVC 4
I assume you use this property in a view with something like EditorFor
? Then use:
[Editable(false)]
public string MyProperty {get;set;}
or
@Html.TextBoxFor(x => x.MyProperty, new { readonly = "readonly" })
If you want a readonly public property of a class use:
public string MyProperty {get; private set;}
@Html.EditorFor(
model => model.id_to_fetch,
new {
htmlAttributes = new {
@class = "form-control" , @readonly = "readonly"
}
}
)