mercredi 30 novembre 2022

How to check checkboxes after submiting as same as previously checked?

case is , First I checked few check box and than submit it , even after clicking on submit the checkbox should be checked as previously selected. Please help me in achieving it. For example have a look at Custom filter in stack overflow this is my HTML code:

<form asp-controller="Student" asp-action="FilterStu">
                    <div class="dropdown">
                        <div class="selectBox" onclick="showCheckboxes()">
                            <select class="btn btn-outline-secondary">
                                <option style="color:darkturquoise">
                                    Filter
                                </option>
                            </select>
                            <div class="overSelect"></div>
                        </div>
                        <div id="checkboxes" class="dropdown-content" >
                            <ul>
                                <label clasenter image description heres="labelclass" style="color:cornflowerblue"><u><i class="bi bi-book-half"></i>Courses</u></label>
                                <li>
                                    <input class="cb" name="searchString1" type="checkbox" id="Int" value="Java" />&nbsp;&nbsp;Java
                                </li>
                                <li>
                                    <input name="searchString2" type="checkbox" id="Int" value="C+" />&nbsp;&nbsp;C++
                                </li>
                                <li>
                                    <input name="searchString3" type="checkbox" id="Int" value="Python" />&nbsp;&nbsp;Python
                                </li>
                                <label style="color:cornflowerblue"><i class="bi bi-people"></i> <u>Gender</u></label>
                                <li>
                                    <input name="gender" type="checkbox" id="Int" value="Male" />&nbsp;&nbsp;Male
                                </li>
                                <li>
                                    <input name="gender" type="checkbox" id="Int" value="Female" />&nbsp;&nbsp;Female
                                </li>
                                <label style="color:cornflowerblue"><i class="bi bi-sort-alpha-down"></i><u>Sorting</u></label>
                                <li>
                                    <input name="sortByAz" type="checkbox" id="Int" value="sort" />&nbsp;&nbsp;Sort by A-Z
                                </li>
                                <li>
                                    <input name="sortByZa" type="checkbox" id="Int" value="sort" />&nbsp;&nbsp;Sort by Z-A
                                </li>
                                </p>
                                <button class="btn btn-outline-success my-2 my-sm-0" type="submit"><i class="bi bi-search"></i>&nbsp;&nbsp;</button>
                                <button class="btn btn-outline-warning" type="submit" asp-action="Index" asp-controller="Student"><i class="bi bi-house"></i>Clear</button>
                            </ul>
                        </div>
                    </div>
                </form>

I tried creating arrays of checked items and Creating Viewbag for each




Aucun commentaire:

Enregistrer un commentaire