Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should get you started.</p> <p>Your Models:</p> <pre><code>public class FooContainer { public int ID { get; set; } public string Name { get; set; } public IList&lt;Foo&gt; Foos { get; set; } } public class Foo { public string Name {get; set; } public string Description {get; set;} } </code></pre> <p>Your Controller Actions:</p> <pre><code>[HttpGet] public ActionResult Foo() { var model = new FooContainer(); return View("Foo", model); } [HttpPost] public ActionResult Foo(FooContainer model) { ViewBag.Test = m.Foos[1].Name; return View("Foo", model); } </code></pre> <p>Your View:</p> <pre><code>@model DriveAway.Web.Models.FooContainer @using(Html.BeginForm()) { &lt;p&gt;@Html.TextBoxFor(m =&gt; m.ID)&lt;/p&gt; &lt;p&gt;@Html.TextBoxFor(m =&gt; m.Name)&lt;/p&gt; for (int i = 0; i &lt; 5; i++) { &lt;p&gt;@Html.TextBoxFor(m =&gt; m.Foos[i].Name)&lt;/p&gt; &lt;p&gt;@Html.TextBoxFor(m =&gt; m.Foos[i].Description)&lt;/p&gt; } &lt;button type="submit"&gt;Submit&lt;/button&gt; } @ViewBag.Test </code></pre> <p>What happens here is when you press submit, the iList will be sent to your HttpPost Foo() action and there you can do whatever you want with it. In my example, it'll show whatever was input into the second Name text box. You can obviously loop through each value and check if filled out etc. e.g.</p> <pre><code>foreach (var f in m.Foos) if (!string.IsNullOrEmpty(f.Name) &amp;&amp; !string.IsNullOrEmpty(f.Description)) addToDB(f); // some method to add to to a database </code></pre> <p>In the view i used a <code>for loop</code> with a limit of 5. But this is obviously up to you. </p>
    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.
 

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