【问题标题】:Fetching the selected dropdown id from jQuery in ASP.NET MVC在 ASP.NET MVC 中从 jQuery 获取选定的下拉列表 id
【发布时间】:2017-12-12 23:26:21
【问题描述】:

我现在拥有的是; 2 个案例的 2 个视图。

第一个视图;假设员工登录,然后他可以单击“我的统计信息”并查看他的日历视图,没有下拉菜单 对他们可见。

第二个视图;让我们假设一个部门负责人登录,然后他可以点击“我的统计”来查看他的日历视图 以及他可以点击“我的部门”查看该部门所有团队的下降,点击 一个团队,另一个下拉列表会填充该团队中的所有成员。

现在发生了什么?

日历视图是根据登录的employeeID生成的,而我正在努力的部分是获取 从 showMembers 下拉列表中选择 memberID。

更新:

@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.
}

假设上述情况是显示“否”下拉列表时,我可以轻松地将会话值分配给 id。但是当显示下拉列表时,我需要从下拉列表中获取 id。

【问题讨论】:

  • 请按照如何创建a Minimal, Complete, and Verifiable example 的指南,尝试将您的代码简化为您遇到的特定问题。
  • $("#ddEmployeeId").val() 应该在调用时获取 EmployeeId 选择中所选选项的值。这是一个 javascript / jquery 问题,也许您应该查看从 Html.DropdownList() 生成的 html
  • @chade_ 我只是想成为水晶,问题出在showCal 函数中,如果有一个依赖下拉列表showMembers,我需要获取该ID并将其分配给id那个函数。

标签: c# jquery asp.net-mvc


【解决方案1】:
@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();
}

或为两个下拉菜单指定一个类,然后您可以按类选择器进行选择。

例如:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    相关资源
    最近更新 更多