This is a migrated thread and some comments may be shown as answers.

[Solved] Problem with "ReadOnly" attribute in Edit Mode

1 Answer 191 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Maria
Top achievements
Rank 1
Maria asked on 24 Dec 2010, 01:22 PM
Hi All!!
I'm, using the "ReadOnly" attribute in  a class for a column that I want to show in the Grid, but I donĀ“t want to edit. If in the Grid, I select the "GridEditMode" as InLine the "ReadOnly" attribute works O.K., but If I change "GridEditMode" to "InForm" or "PopUp", the attribute does not work....
Is it not supported in "InForm" or "PopUp" or I'm missing something ?????   

Thanks

Maria

1 Answer, 1 is accepted

Sort by
0
Danan
Top achievements
Rank 1
answered on 01 Feb 2011, 06:54 PM
You need to create an EditorTemplate for the Type. Then only render properties that are not read only like so:

@if (ViewData.TemplateInfo.TemplateDepth > 1)
{
    <text>@ViewData.ModelMetadata.SimpleDisplayText</text>
}
else
{
    <table  cellpadding="0" cellspacing="0" border="0">
    <tr><td>User Edit</td></tr>
        @foreach (var property in ViewData.ModelMetadata.Properties.Where(p => p.ShowForEdit && !p.IsReadOnly && !ViewData.TemplateInfo.Visited(p)))
        {
            <tr>
                <td>@Html.Label(property.PropertyName):</td>
                <td>@Html.Editor(property.PropertyName)</td>
            </tr>
        }
    </table>
}
Tags
General Discussions
Asked by
Maria
Top achievements
Rank 1
Answers by
Danan
Top achievements
Rank 1
Share this question
or