In my asp.MVC application I have created two combo boxes as Manager and TopManager.
I have loaded Manager list to the Temp list and another Temp list to the Top managers list.
@using Asp_PASMVC.Infrastructure
@{
List<SelectListItem> Employees = (List<SelectListItem>)TempData.Peek("EmployeeList");
List<SelectListItem> TopEmp = (List<SelectListItem>)TempData.Peek("TopEmpDroDown");
if (Employees.Exists(x => x.Value == "1"))
{
Employees.Where(x => x.Value == "1").First().Selected = true;
}
if (TopEmp.Exists(x=> x.Value =="1"))
{
TopEmp.Where(x => x.Value == "1").First().Selected = true;
}
string UserLvel = TempData.Peek("UserLevelClaims").ToString();
}
Here is the View
<li style="padding-bottom:15px">
@using (Html.BeginCollectionItem("ApprovalPartyList"))
{
<div class="row">
<div class="col-md-3 col-sm-6">
<div class="form-group row">
For Manager
<div class="col-sm-8">
@Html.RadioButtonFor(m => m.Approve_Type, false)
</div>
</div>
</div>
@if (UserLvel != "1")
{
<div class="col-md-4 col-sm-6">
<div class="form-group row">
For Top Manager
<div class="col-sm-8">
@Html.RadioButtonFor(m => m.Approve_Type, true)
</div>
</div>
</div>
}
</div>
<br />
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group row">
Select the Approver
<div class="col-sm-8">
@Html.DropDownListFor(model => model.Approver_Id, Employees, new { @class = "js-dropdown" })
@Html.ValidationMessageFor(model => model.Approver_Id, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-danger" onclick="$(this).parent().remove();">Delete</button>
}
</li>
<script>
$('.js-dropdown').select2({
width: '100%', // need to override the changed default
});
</script>
The issue is combo box only shows the Manager list (I have assigned ), I want it to change If Radio button Manager selected the combo box should load the 'Employees' and If 'Top Manager' Selected, Should load the 'TopEmp' list to the combo box.
This is my unfinished script.
<script>
$('#Approve_Type').change(function () {
if ($(this).val() == false)
{
alert('', 'Manager Selected');
} else {
alert('', 'TopManager Selected');
}
});
</script>
alert should replace with the code which i pass to the combobox list. I cannot complete the code