简体   繁体   中英

Hide KendoUI Dropdownlist

I am trying to hide/show a KendoUI Dropdownlist depending on the user's level of access; so that it would be only visibile for AdminUsers

@if (User.IsInRole(Constants.Admin))
{
<div>
    <div class="editor-label">
        Filter by Staff:
    </div>
    <div class="editor-field">

        @(Html.Kendo().DropDownList().Name("UserDropDownList").BindTo(Model.Users)
                .DataTextField("User").DataValueField("UserId")
                .SelectedIndex(Model.Users.IndexOf(Model.Users.FirstOrDefault(x => x.UserId == Model.Default)))
                .Events(e => e.Change("SelectedUserChanged")))
    </div>
</div>

}

Now this wont work when the user is not an admin because as you see, this Dropdownlist has a Change event which feeds a Grid. I wonder if there is anyway that you're aware of to resolve this issue. Many thanks.

You could bring the dropdown hidden and at document ready of javascript call a action on controller that tells you if you can show or not the dropdown ($("#UserDropDownList").show() you can also use .hide()). And if you need you can trigger manually.

 $("#UserDropDownList").data("kendoDropDownList").trigger("change");

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