Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all you shouldn't be iterating in a view. Iterating means loops, loops mean C#/VB.NET, C#/VB.NET in a view leads to spaghetti code. </p> <p>I would recommend you using <a href="http://blogs.msdn.com/b/nunos/archive/2010/02/08/quick-tips-about-asp-net-mvc-editor-templates.aspx" rel="noreferrer">Editor Templates</a>. This way you don't need to write loops in your views. Add the following file in <code>~/Views/Home/EditorTemplates/PictureModel.ascx</code>:</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;whoozit.Models.PictureModel&gt;" %&gt; &lt;td&gt; &lt;%: Html.TextBoxFor(x =&gt; x.name) %&gt; &lt;%: Html.ValidationMessageFor(x =&gt; x.name) %&gt; &lt;/td&gt; </code></pre> <p>Notice that the partial is now strongly typed to <code>whoozit.Models.PictureModel</code> instead of <code>IList&lt;whoozit.Models.PictureModel&gt;</code>. Now all that is left is to include this partial from the main view:</p> <pre><code>&lt;%: Html.EditorFor(x =&gt; x.Pictures) %&gt; </code></pre> <p>Where <code>Pictures</code> is a property of type <code>IList&lt;whoozit.Models.PictureModel&gt;</code> on your main view model. This will automatically invoke the partial for each element of the collection so that you don't need to write ugly loops in your views.</p> <p>It just works by convention: the partial needs to be called <code>PictureModel.ascx</code> as the type name of the list elements and located in <code>~/Views/Home/EditorTemplates</code> or <code>~/Views/Shared/EditorTemplates</code> folder. </p> <p>Editor/Display templates will make your views much more elegant.</p> <p>Remark: In .NET the convention is property names to start with capital letter, so I would recommend you renaming the <code>name</code> property to <code>Name</code>. It's just feels more natural to write and read:</p> <pre><code>&lt;%: Html.TextBoxFor(x =&gt; x.Name) %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload