How can I use Html.DisplayFor inside of an iterator?

Viewed 24211

I am loving MVC 2. The whole thing just fits the web so well.

There is one piece of functionality, however, that I am unable to coax out of the Html.DisplayFor() function:

<@ Page Inherits="ViewPage<IEnumerable<Foo>>">

<% foreach(var item in Model) { %>

    <%: Html.DisplayFor(item.BarBaz) %>

<% } %>

I need to be able to use the DisplayTemplate for this value. Is there a way to do this?

6 Answers

Just be careful that a DisplayFor on a POST of a form doesnt actually create a field that can be referenced back in the controller. You would need to use an additional HiddenFor if you need to refer to fields in your submitted POST method.

Related