Creating a SelectListItem with the disabled=“disabled” attribute

后端 未结 5 975
感情败类
感情败类 2020-12-05 07:01

I\'m not seeing a way to create, via the HtmlHelper, a SelectListItem that will spit out the following HTML:

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 07:32

    Clientside option: if you for example give your dropdownlist a class 'custom' and the items that should be unselectable the value -1 (for example), then you can do something like:

    $('select.custom option[value=-1]').each(function () {
        $(this).attr("disabled", "disabled");
    });
    

提交回复
热议问题