Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let's modify your model a little:</p> <pre><code>public class ItemViewModel { public string Id { get; set; } public string Name { get; set; } public bool Checked { get; set; } } </code></pre> <p>then you could have a controller:</p> <pre><code>public class HomeController: Controller { public ActionResult Index() { // This action is used to render the form =&gt; // we should populate our model with some values // which could obviously come from some data source var model = new[] { new ItemViewModel { Id = "1", Checked = true, Name = "item 1" }, new ItemViewModel { Id = "2", Checked = false, Name = "item 2" }, new ItemViewModel { Id = "3", Checked = true, Name = "item 3" }, }; return View(model); } [HttpPost] public ActionResult Index(IEnumerable&lt;ItemViewModel&gt; items) { // This action will be invoked when the form is submitted // and here the view model will be properly bound and // you will get a collection of all items with their // corresponding id, name and whether they were checked or not ... } } </code></pre> <p>then you would have a corresponding view (<code>~/Views/Home/Index.cshtml</code>) which would contain the form allowing the user to check/uncheck values:</p> <pre><code>@model IEnumerable&lt;AppName.Models.ItemViewModel&gt; @using (Html.BeginForm()) { @Html.EditorForModel() &lt;input type="submit" value="OK" /&gt; } </code></pre> <p>and finally the editor template (<code>~/Views/Home/EditorTemplates/ItemViewModel.cshtml</code>):</p> <pre><code>@model AppName.Models.ItemViewModel // Those two hidden fields are just to persist the id and name @Html.HiddenFor(x =&gt; x.Id) @Html.HiddenFor(x =&gt; x.Name) &lt;div&gt; @Html.CheckBoxFor(x =&gt; x.Checked) @Html.LabelFor(x =&gt; x.Checked, Model.Name) &lt;/div&gt; </code></pre>
 

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