Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the value of the row that has been checked
    primarykey
    data
    text
    <p>I have a model that contain a list of category, the categories are displayed using a table on a web page, I want to add a check box to each roll so that I can select multiple role and delete them all at once, I could do that using Knockout, but I want to do it without using Knockout. How do I go about getting the row value especially the ID column for row that are checked, I tried following the answer gave here <a href="https://stackoverflow.com/questions/17544444/getting-values-of-check-box-from-formcollection-in-asp-net-mvc">Getting values of check-box from formcollection in asp.net mvc</a> but it is not working. Any Ideas Thanks.</p> <p>Below is a sample code for my model</p> <pre><code>public class Category { public Category() { CreatedOn = DateTime.Now; } /// &lt;summary&gt; /// Category unique identification /// &lt;/summary&gt; [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ID { get; set; } /// &lt;summary&gt; /// Name of the category /// &lt;/summary&gt; [Required(AllowEmptyStrings = false, ErrorMessage = "Can't be left empty")] [StringLength(500, MinimumLength = 2, ErrorMessage = "An Error has occured, check your input and try agian")] public string Name { get; set; } </code></pre> <p>Below is the code for my view model</p> <pre><code>public class CategoryViewModel { public CategoryViewModel(UnitOfWork _unitofWork) { CategoryList = _unitofWork.CategoryRepo.GetAll().ToDictionary(v =&gt; v, v =&gt; IsSelected); } public IDictionary&lt;Category, bool&gt; CategoryList { get; private set; } public bool IsSelected {get; private set; } } </code></pre> <p>for my view</p> <pre><code>&lt;table class="table table-striped table-hover" id="sample_1"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th style="width: 8px;"&gt; &lt;input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes" /&gt; &lt;/th&gt; &lt;th&gt;ID&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; @foreach (var item in Model.CategoryList) { &lt;tr class="odd gradeX"&gt; &lt;td&gt; @Html.CheckBoxFor(m =&gt; m.IsSelected, item.value) &lt;/td&gt; &lt;td&gt;@item.ID&lt;/td&gt; &lt;td&gt;@item.Name&lt;/td&gt; &lt;/tr&gt; } &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>and my controller action</p> <pre><code>public ActionResult DeleteCat(string[] IsSelected) </code></pre> <p>For example if there are 3 row and none is checked the <code>IsSelected</code> parameter of the Action is populated with just the value of false representing each role, but if one row is checked the <code>IsSelected</code> parameter is populated with both the value of true and false for that row. How do I get just true for any selected row instead of getting true and false?</p>
    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.
 

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