Accessing fields from View

Topics: Troubleshooting, Writing modules
Feb 16, 2012 at 6:56 AM

I'm writing a module for a membership site.  I've installed the Profile module & written a MemberPart which I've attached to the User content type. The MemberPart only has essential fields defined in the code (FirstName, LastName) & I'm adding other fields via the UI, like Telephone, Mobile etc. Displaying and editing the user profiles works great. 

But now I want to display all the members in a grid.  I'm having trouble displaying the extra fields. 

The <th> elements work great, the field headings are displayed, but the <td> value cells display "Orchard.Core.Common.Fields.TextField.Value" instead of the value.  

@model LETS.ViewModels.MemberListViewModel

        <table class="items">
            <thead>
                <tr>
                    <th scope="col">@T("UserName")</th>
                    <th scope="col">@T("Email")</th>
                    <th scope="col">@T("First name")</th>
                    <th scope="col">@T("Last name")</th>
                    @foreach (var field in Model.MemberPartDefinition.Fields)
                    {
                        <th scope="col">@field.DisplayName</th>
                    }
                </tr>
            </thead>
            @foreach (var member in Model.Members)
            {
            <tr>
                <td>
                    @Display(New.Profile_LinkFor(UserName: member.User.UserName))
                </td>
                <td>
                    @member.User.Email
                </td>
                <td>
                    @member.FirstName
                </td>
                <td>
                    @member.LastName
                </td>
                    @foreach (var field in member.Fields)
                    {
                        // just handle text fields for now
                        if (field.FieldDefinition.Name.Equals("TextField"))
                        {
                            <td>@((TextField)field).Value</td>
                        }
                    }
            </tr>
            }
        </table>

Feb 17, 2012 at 5:37 AM

ok I figured it out :-)  That syntax is giving the view an object but not saying what to do with it.  So wrap it in a Display() to get the value.

@Display(((TextField)field).Value)