function selectType(items, type) { return items.select(x => x.ObjectType === type).map(x => x.Checked = true); }
var list = JsonConvert.SerializeObject(@table); <form asp-controller="Consumer" asp-action="" method="post"> <div class="row justify-content-end" style="margin-top: 20px; margin-bottom: 20px;"> @foreach (var type in ObjectTypes.All) { <label style="margin-right: 10px;"> <input onclick="selectType(@list, @type)" style="margin-right: 5px;" type="checkbox" id="@type" name="type" value="@type">@type </label> } </div> <table class="table table-striped"> <thead> <tr> <th>#</th> <th></th> <th>Object Id</th> <th>Object type</th> </tr> </thead> <tbody> @if (table.Count > 0) { @for (int i = 0; i < table.Count; i++) { <input type="hidden" name="@("items[" + i + "].ObjectId")" value="@table[i].ObjectId"/> <input type="hidden" name="@("items[" + i + "].ObjectType")" value="@table[i].ObjectType"/> <tr> <td>@(++id)</td> <td> <input name="@("items[" + i + "].Checked")" type="checkbox" value="true" @(table[i].Checked ? "checked" : " ")/> </td> <td>@table[i].ObjectId</td> <td>@table[i].ObjectType</td> </tr> } } </tbody> </table> </form>
var selectedKeys = Request.Form.Keys.Where(k=> k.EndsWith(".Checked", System.StringComparison.OrdinalIgnoreCase));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)