Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将DropDownList的选定索引更改为第一个索引,同时将复选框更改为未选中模式_C#_Jquery_Asp.net Mvc - Fatal编程技术网

C# 将DropDownList的选定索引更改为第一个索引,同时将复选框更改为未选中模式

C# 将DropDownList的选定索引更改为第一个索引,同时将复选框更改为未选中模式,c#,jquery,asp.net-mvc,C#,Jquery,Asp.net Mvc,在我的ASP.NET MVC项目中,我有一个复选框,当我选中该复选框时,将出现一个下拉列表,我可以从该下拉列表中选择一个项目(我指的是组合框中第一个项目除外),但当我取消选中该复选框时,下拉列表中的选定项目必须是第一个索引(我的意思是-): 我的复选框(切换按钮)如下所示: <div style="margin-top: 30px;margin-right: 8px" class="row col-md-7"> <p>آیا شاغل هستید؟</p>

在我的ASP.NET MVC项目中,我有一个复选框,当我选中该复选框时,将出现一个下拉列表,我可以从该下拉列表中选择一个项目(我指的是组合框中第一个项目除外),但当我取消选中该复选框时,下拉列表中的选定项目必须是第一个索引(我的意思是-):

我的复选框(切换按钮)如下所示:

<div style="margin-top: 30px;margin-right: 8px" class="row col-md-7">
  <p>آیا شاغل هستید؟</p><label style="margin-top: -7px;margin-right: 20px" class="switch">
     <input class="switch-input" type="checkbox"  value="true" name="JobStatus"/>
     <span class="switch-label" data-on="هستم" data-off="نیستم"></span> <span class="switch-handle"></span>
     </label>
</div>
<div class="col-md-7" hidden="hidden" id="divJobsId" style="margin-top: 30px" tooltip="شغل" flow="down">
   @Html.DropDownList("JobsId", null, "- شغل را انتخاب نمایید -", htmlAttributes: new { type = "Text", @class = "form-control" })
   @Html.ValidationMessageFor(model => model.JobsId, "", new { @class = "text-danger" })
</div>

我该如何解决这个问题?如果有任何帮助,我们将不胜感激!

您不会清除基于复选框或未选中复选框的选择?您好,您的意思是什么?您的意思是无法将DropDownList所选项目返回到第一个项目中(“-取消选中复选框后?如果没有办法,我将遇到大问题。您希望在下拉列表中选择您已经选中的数据吗?不,想象一下,当我选中复选框时(当我选中复选框时,我想说我有工作,当复选框未选中时,我没有工作)此时,下拉列表出现,我从下拉列表中选择了“例如”,但再次取消选中复选框,下拉列表被隐藏,此时,下拉列表中的选定项必须是第一项(“-1588-”)如果未选中该复选框,则不必选择DropDownList中的任何作业
 $(document).ready(function () {
        $('.switch-input').change(function () {
            debugger;
            if (this.checked) {
                $("#divJobsId").prop('hidden', false);
            } else {
                $("#divJobsId").prop('hidden', true);
                $("#JobsId").prop('show', false);
            }
            if ($("#divJobsId").is(':visible')) {
                $("#JobsId").chosen();
            }
        });
    });