I work on asp.net mvc I face issue selected value All requests cleared after display result data and back to Pending Request
so my issue on selected value option if i select option All requests it display all requests success but drop down selected option display as Pending Request
so How to solve issue selected option clear after display data
action GetSelectedDropDownChanged on controller WorkforceRequests hit and catched when make debug and detect value 1 if i select pending request and 2 if i select all request
but issue when select option All request it back to option Pending Request so How to prevent this behaviour from happen
code details
on controller WorkforceRequestsController
public async Task GetSelectedDropDownChanged() //Assuming key in your dropdown is string
{
string selectedValue = Request.Form["statusselect"].ToString();
List workforceRequest = new List();
if (selectedValue == "1")
{
workforceRequest = Workforce.GetPendingOnPalnningSection(RoleKey.PLS);
}
else
workforceRequest = Workforce.GetAllRequestsOnPalnningSection(RoleKey.PLS);
return View(workforceRequest);
}
Amit MohantyPosted Jul 17, 2023, 9:32 AM
try this
ahmed salahPosted Jul 17, 2023, 9:07 AM
thanks for support issue still exist
it refresh page and after refresh go to first item
ful code
from debug funtion it detect as viewbage have value 2 but it got first item 0 as select status
so how to solve this issue
Amit MohantyPosted Jul 17, 2023, 7:43 AM
If you don't have a property named SelectedOption in your existing model, you can create a separate class to hold the selected option value or can use the ViewBag, ViewData. So here an example using ViewBag.
ahmed salahPosted Jul 17, 2023, 7:02 AM
thanks for support
but Model.SelectedOption
I don't have any property on Model name selectedoption
so what i do to add make that please
Amit MohantyPosted Jul 17, 2023, 5:58 AM
I think the issue lies in the way the selected value is being handled in the controller. Currently, the selected value is not being passed back to the view after the form submission, which is causing the dropdown to revert to its default value upon displaying the result data. Check the below code this may help you: