Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing model back to controller with checkboxes comes back empty
    primarykey
    data
    text
    <p>trying to grasp how to pass back the following data as a model to the controller. I want to consume the model and add everything to a database afterwards. When I submit the form back to the controller, the model is empty. Is it because every thing else is null? do I have to pass everything else back as hidden fields? How do I sort that all out on the View before getting to the controller?</p> <p>My controller basically deserializes an xml file that looks like this back to the view</p> <pre><code>&lt;category&gt; &lt;id&gt;1&lt;/id&gt; &lt;description&gt;movies&lt;/description&gt; &lt;genre&gt; &lt;genres&gt; &lt;id&gt;1&lt;/id&gt; &lt;name&gt;comedy&lt;/name&gt; &lt;/genres&gt; &lt;genres&gt; &lt;id&gt;2&lt;/id&gt; &lt;name&gt;action&lt;/name&gt; &lt;/genres&gt; &lt;genres&gt; &lt;id&gt;3&lt;/id&gt; &lt;name&gt;adventure&lt;/name&gt; &lt;/genres&gt; &lt;genres&gt; &lt;id&gt;4&lt;/id&gt; &lt;name&gt;drama&lt;/name&gt; &lt;/genres&gt; &lt;genres&gt; &lt;id&gt;5&lt;/id&gt; &lt;name&gt;romance&lt;/name&gt; &lt;/genres&gt; &lt;/genres&gt; &lt;/category&gt; </code></pre> <p>The view / form looks like this </p> <pre><code> &lt;form&gt; &lt;ul&gt; @for (int x = 0; x &lt; Model.categories[i].genres.Count(); x++) { &lt;li&gt; &lt;label for="@Model.categories[i].genres[x].name"&gt; &lt;input type="checkbox" name="@Model.categories[i].genres[x].name" value="@Model.categories[i].genres[x].id" checked="@Model.categories[i].genres[x].selected" /&gt; @Model.categories[i].genres[x].name &lt;/label&gt; &lt;/li&gt; } &lt;/ul&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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