简体   繁体   中英

Fetching the selected dropdown id from jQuery in ASP.NET MVC

What I have at the moment is; 2 Views for 2 cases.

First View; Lets suppose an employee logs in, he can then click on "My Stats" and view his calendar view, no dropdown is visible to them.

Second View; Lets assume a department head logs in, he can then click on "My Stats" to view his calendar view as well as he can click on "My Department" to view a drop with all the teams in that department, upon clicking on a team, another dropdown populates with all the members in that team.

Now What is happening?

The calendar view is generated on the basis of the employeeID logged in, and the part where I am struggling is to get the selected memberID from the showMembers dropdown list.

UPDATED:

@section scripts{
    <script>
        function showCal() {
                       id = $('#EmployeeId').val();
                       if (id == null)
// tackle the checks for different IDs here right now id is null and current empID's record is shown
                            id = @Session["currentEmpID"].ToString();
else
{
//fetch the id from ddshowMembers here, the if() part is running in all conditions.
}

Lets assume the above scenario is when "no" dropdownlist is shown, I can then easily assign the Session value to id. But when the dropdownlist is shown I need to fetch the id from the dropdownlist.

@section scripts{
    <script>
        function showCal() {
                       id = $('#EmployeeId').val();
                       if (id == null)
// tackle the checks for different IDs here right now id is null and current empID's record is shown
                            id = @Session["currentEmpID"].ToString();
else
{
id=$('#ddshowMembers').val();
}

or assign a class for both dropdowns then you can select by class selector.

Eg:

@Html.DropDownList("showMembers", null, "-Select Team-", htmlAttributes: new {id = "ddshowMembers", @class = "form-control selected-item" })

var id= $('.selected-item').val();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM