Hi @Ahmed Abd El Aziz,
I think I understand what you need.
What you're saying should be that when the form is submitted, the form resets in preparation for another data entry session. So it will come back to the option "Pending Request".
You can set a value in TempData to keep the selected value, and retrieve TempData in the View page to set the DropDownList value using JavaScript.
<form action="/WorkforceRequests/GetSelectedDropDownChanged" method="post">
<select class="form-control" id="statusselect" name="statusselect">
<option value="1">Pending Request</option>
<option value="2">All requests </option>
</select>
<input type="submit" value="Submit" />
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
@if (TempData["statusselect"] != null)
{
<script type="text/javascript">
$(function () {
$("#statusselect").val(@TempData["statusselect"]);
});
</script>
}
</form>
[HttpPost]
public async Task<ActionResult> GetSelectedDropDownChanged() //Assuming key in your dropdown is string
{
string selectedValue = Request.Form["statusselect"].ToString();
List<WorkforceRequest> workforceRequest = new List<WorkforceRequest>();
//.........
TempData["statusselect"] = selectedValue;
return View(workforceRequest);
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.