我正在尝试使用mvc JavaScript函数启用/禁用下拉列表

我正在尝试使用mvc JavaScript函数启用/禁用下拉列表,javascript,asp.net-mvc,razor,Javascript,Asp.net Mvc,Razor,我试图在未选中启用复选框时禁用这些下拉列表。这是我的第一次尝试,任何指导都将不胜感激 基本上,当复选框被禁用时,我会尝试禁用下拉列表。选中复选框后,需要启用下拉列表 js: cshtml: <section class="well "> <div class="row"> <div class="col-lg-12 gutter-0"> <div class="row gutter-0">

我试图在未选中启用复选框时禁用这些下拉列表。这是我的第一次尝试,任何指导都将不胜感激

基本上,当复选框被禁用时,我会尝试禁用下拉列表。选中复选框后,需要启用下拉列表

js:

cshtml:

<section class="well ">
<div class="row">
    <div class="col-lg-12 gutter-0">

        <div class="row gutter-0">                
            <div class="col-sm-6 col-md-6 col-lg-8">
                <div class="box-placeholder">
                    <div>
                        @Html.Label(Resources.USERS_Settings, htmlAttributes: new { @class = "control-label", maxlength = "15", style = "font-weight: bold; font-size: 15px; display: inline;" })
                    </div><br />
                    <div>
                        @Html.Kendo().CheckBoxFor(model => model.EnableUserLogin.BoolValue).Label(Resources.Users_EnableSecurity).HtmlAttributes(new { @class = "cti-db-numvalue cti-up-EnableUserLogin", id = "userPermissions", type = "checkbox" })

                        @Html.ValidationMessageFor(model => model.EnableUserLogin, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-12 gutter-0">               
            <div class="col-sm-6 col-md-6 col-lg-8">
                <div class="box-placeholder">
                    @Html.Kendo().CheckBoxFor(model => model.EnableTransferOnLoginScreen.BoolValue).Label(Resources.Users_EnableTransferOnLoginScreen).HtmlAttributes(new { @class = "cti-db-numvalue cti-up-EnableTransferOnLoginScreen" })
                </div><hr />
            </div>
        </div>
    </div>
    <div class="col-sm-12 col-md-12 col-lg-12">
        <div class="row gutter-10">
            <div class="col-sm-6 col-md-6 col-lg-8">
                <div id="userSettingsBottom" class="box-placeholder" style="outline: none;">
                    <div>
                        @Html.Label(Resources.USERS_CustomFieldOption, htmlAttributes: new { @class = "control-label", style = "font-weight: bold; font-size: 14px; display: inline;" })&nbsp
                        @Resources.USERS_SelectedField
                    </div>
                    <div class="col-sm-4 col-md-4 col-lg-4">
                        <div>
                            @Html.Label(Resources.Users_InboundUserIDField, htmlAttributes: new { @class = "control-label" })
                        </div>
                        @Html.Kendo().DropDownListFor(model => model.InboundUserIDField).HtmlAttributes(new { @class = "cti-db-numvalue cti-up-InboundUserIDField" })
                    </div>
                    <div class="col-sm-4 col-md-4 col-lg-4">
                        <div>
                            @Html.Label(Resources.Users_DeliverUserIDField, htmlAttributes: new { @class = "control-label" })
                        </div>
                        @Html.Kendo().DropDownListFor(model => model.DeliverUserIDField).HtmlAttributes(new { @class = "cti-db-numvalue cti-up-DeliverUserIDField" })
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

既然这些是剑道下拉列表,为什么不使用剑道功能呢?首先,名称应该从model字段派生。在这种情况下,model.DeliverUserIDField的默认示例为

$("#DeliverUserIDField").data("kendoDropDownList").enable(false);

到底出了什么问题?调试表明代码中当前正在发生什么?我看到您添加了一些日志记录,所以您大概可以基于此描述当前的行为?TBH因为JS是在HTML上运行的,所以在代码中看到最终呈现的HTML的示例比Razor源代码更有用。但是如果我不得不猜测,我可能会说,因为您的事件处理程序声明在document.ready块之外,那么它们可能是在呈现HTML之前执行的,因此找不到任何要将事件附加到的元素。这取决于代码中的什么地方你的是@MarkFitzpatrick谢谢你,我在正确的轨道上!在我发布这个问题之后,我实际上正在实现剑道特性。
$("#DeliverUserIDField").data("kendoDropDownList").enable(false);