Rajesh Yadav

Rajesh Yadav

  • NA
  • 105
  • 7.8k

Dropdownlist not hold selected value while use pagination

Apr 2 2020 11:31 AM
Does not hold selected value AA while using pagination. When moving to another page, dropdownlist moves to state All.
 
Used ViewBag to store the current filter state but no luck.
 
No idea where to go and change the code to make it work. Can anyone enlighten me the way to do this.
  1. Public async Task<IActionResult> Index(string searchText, string currentFilter, int? page)  
  2. {  
  3. int selectedPage = page ?? 1;  
  4. int bypassCount = (selectedPage - 1) * _pagingOptions.PageSize;  
  5. if (searchText != null) { page = 1; }  
  6. else { searchText = currentFilter; }  
  7. ViewBag.CurrentFilter = searchText;  
  8. }  
index
  1. <form asp-action="Index" method="get">  
  2. <select class="custom-select" asp-for="searchText" value="@(ViewBag.CurrentFilter)">  
  3. <option value="">All</option>  
  4. <option value="AA">AA</option>  
  5. <option value="AE">AE</option>  
  6. <option value="AR">AR</option>  
  7. </select>  
  8. <div class="col-md-12">  
  9. <button class="btn btn-primary" type="submit">Search</button>  
  10. </div> </form>  
  11. <table class="table"> <thead> <tr > <th>Resent</th> <th>Resent Date</th> <th>Created Date</th> </tr> </thead> <tbody> @if (Model.Items.TotalItemCount > 0)  
  12. {  
  13. @foreach (var item in Model.Items.ToList())  
  14. {  
  15. <td>@Html.DisplayFor(modelItem => resentString)</td>  
  16. <td>@Html.DisplayFor(modelItem => resentDateString)</td>  
  17. <td>@Html.DisplayFor(modelItem => createdDateString)</td> </tr>  
  18. } }  
  19. </tbody> </table> </div>  
  20. @if (Model.Items.PageCount > 1)  
  21. {  
  22. @Html.PagedListPager(Model.Items, page => Url.Action("Index"new {  
  23. page = page, currentFilter = ViewBag.CurrentFilter})  
  24. }  

Answers (6)