smc develpments

smc develpments

  • NA
  • 121
  • 1.3k

Setting two different list for combo box with the radio button selecti

Sep 15 2021 4:46 AM

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. I think this shold be done with javascript. But no idea of creating that. Can you help me on this ? Thanks in advance. 


Answers (1)