Your problem is simply to add an "input" control to the View page to pass data to the "controller" and write an overloaded method.
At the same time, in order to achieve better results, you can write a javascript method: use the input control once every time the select control option changes. At the same time, hide the input control to achieve better results.
Code:
[HttpGet]
public ActionResult GetAllEmpDetails()
{
EmpRepository EmpRepo = new EmpRepository();
ModelState.Clear();
return View(EmpRepo.GetAllEmployees());
}
[HttpPost]
public ActionResult GetAllEmpDetails(string MovieType)
{
EmpRepository EmpRepo = new EmpRepository();
ModelState.Clear();
int A = Convert.ToInt32(MovieType);
return View("GetAllEmpDetails", EmpRepo.LoadDropDownLists(A));
}
public ActionResult CategoryChosen(string MovieType)
{
ViewBag.messageString = MovieType;
return View(MovieType,"GetAllEmpDetails");
}
@{
ViewBag.Title = "GetAllEmpDetails";
}
<h2>GetAllEmpDetails</h2>
<script type="text/javascript">
function Onchange() {
document.getElementById("up").click();
}
</script>
<form action="/Employee/GetAllEmpDetails" method="post" >
<select id="MovieType" name="MovieType" onchange="Onchange()" >
<option value=""></option>
<option value="1">Pending Request</option>
<option value="2">Done Request</option>
</select>
<input id="up" type="submit" value="submit" hidden="hidden" />
</form>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.EmployeeId)
</th>
<th>
@Html.DisplayNameFor(model => model.EmployeeName)
</th>
<th>
@Html.DisplayNameFor(model => model.EmployeeStatus)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.EmployeeId)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmployeeName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmployeeStatus)
</td>
</tr>
}
</table>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.EmployeeId)
</th>
<th>
@Html.DisplayNameFor(model => model.EmployeeName)
</th>
<th>
@Html.DisplayNameFor(model => model.EmployeeStatus)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.EmployeeId)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmployeeName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmployeeStatus)
</td>
</tr>
}
</table>
Result
This is the more commonly used form method for asp.net MVC. Of course, you can use ajax to achieve better results. If you need, please leave a message and I will provide it to you.
Best Regards
Qi You
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.