views:

212

answers:

1

I'm building a table of data like this

<% foreach (var person in Model.People)
{
%>
    <tr>
        <td><%= Html.ActionLink(accessory.Name, "EditPerson") %></td>
        <td><%= Html.DisplayFor(c => person.Name) %></td>
        <td><%= Html.DisplayFor(c => person.Age) %></td>
        <td><%= Html.DisplayFor(c => person.Budget)%></td>
    </tr>
<%} %>

I've created templates to override the defaults following Brad Wilson's tutorial:

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<script runat="server">
    protected override void OnInit(EventArgs e) {
        base.OnInit(e);

        if (ViewData.ModelMetadata.HideSurroundingHtml) {
            TablePlaceholder.Visible = false;
        }
        else {
            Controls.Remove(Data);
            DataPlaceholder.Controls.Add(Data);
        }
    }
</script>
<asp:ContentPlaceHolder runat="server" id="Data" />
<asp:PlaceHolder runat="server" id="TablePlaceholder">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td style="width: 10em;">
                <div class="display-label" style="text-align: right;">
                    <asp:ContentPlaceHolder runat="server" id="Label">
                        <%= ViewData.ModelMetadata.GetDisplayName() %>
                    </asp:ContentPlaceHolder>
                </div>
            </td>
            <td>
                <div class="display-field">
                    <asp:PlaceHolder runat="server" id="DataPlaceholder" />
                </div>
            </td>
        </tr>
    </table>
</asp:PlaceHolder>

When rendering the table I don't want to display the surrounding HTML, but I don't have a clue how to set the HideSurroundingHtml value?

+3  A: 

According to the MSDN page on ModelMetadata.HideSurroundingHtml Property:

When this property is used with the DataAnnotationsModelMetadataProvider model metadata provider, it is set to true when both the HiddenInputAttribute attribute is true and the DisplayValue property is set to false.

So you need to decorate your property in your model with this:

[HiddenInput(DisplayValue = false)]

I doesn't make any sense to me but it seems to work!

Jonathan Sewell
i'll have to try it, but from gut feeling I think that it is going to render with the hidden template and not the template I want.
adriaanp