TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajesh Yadav
NA
105
8.2k
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.
Public async Task<IActionResult> Index(
string
searchText,
string
currentFilter,
int
? page)
{
int
selectedPage = page ?? 1;
int
bypassCount = (selectedPage - 1) * _pagingOptions.PageSize;
if
(searchText !=
null
) { page = 1; }
else
{ searchText = currentFilter; }
ViewBag.CurrentFilter = searchText;
}
index
<form asp-action=
"Index"
method=
"get"
>
<select
class
=
"custom-select"
asp-
for
=
"searchText"
value=
"@(ViewBag.CurrentFilter)"
>
<option value=
""
>All</option>
<option value=
"AA"
>AA</option>
<option value=
"AE"
>AE</option>
<option value=
"AR"
>AR</option>
</select>
<div
class
=
"col-md-12"
>
<button
class
=
"btn btn-primary"
type=
"submit"
>Search</button>
</div> </form>
<table
class
=
"table"
> <thead> <tr > <th>Resent</th> <th>Resent Date</th> <th>Created Date</th> </tr> </thead> <tbody> @
if
(Model.Items.TotalItemCount > 0)
{
@foreach (
var
item
in
Model.Items.ToList())
{
<td>@Html.DisplayFor(modelItem => resentString)</td>
<td>@Html.DisplayFor(modelItem => resentDateString)</td>
<td>@Html.DisplayFor(modelItem => createdDateString)</td> </tr>
} }
</tbody> </table> </div>
@
if
(Model.Items.PageCount > 1)
{
@Html.PagedListPager(Model.Items, page => Url.Action(
"Index"
,
new
{
page = page, currentFilter = ViewBag.CurrentFilter})
}
Reply
Answers (
6
)
Mix angularjs http error handling and MVC custom page error?
Live video streaming web application using Asp.net c#