Click here to Skip to main content
15,354,522 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have table like showed below. I want to check/uncheck (for now just trying out check) values in the table based on the type I select. Could this be done somehow like this? Or do I somehow need to send request from javascript to see updated values? Or could this be done by using C# only?

What I have tried:

function selectType(items, type) {
  return => 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
              <table class="table table-striped">
                      <th>Object Id</th>
                      <th>Object type</th>
                  @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"/>
                                  <input name="@("items[" + i + "].Checked")" type="checkbox" value="true" @(table[i].Checked ? "checked" : " ")/>
Updated 8-May-22 23:35pm

1 solution

Maybe the form collection is a solution:

var selectedKeys = Request.Form.Keys.Where(k=> k.EndsWith(".Checked", System.StringComparison.OrdinalIgnoreCase));


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900