0

I want to disable the first element "Accreditation" as it is only a label but when it gets selected I get exception. To avoid it it should be disable by-default and after it next first element should get selected

@Html.DropDownListFor(model => model.ReportTemplate.AccreditationId, 
                      Model.lstAccrediation, 
                      "Accreditation", 
                      new { @class = "selectmenu", @id = "ddlAccreditationId", 
                            data_val = "false" })
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
AnumShk
  • 47
  • 10
  • Check [here](https://stackoverflow.com/questions/14198870/disable-first-item-in-dropdownlist?rq=1); in your controller, for the submission of the form, you could require `if (dd.SelectedIndex != 0)` where `dd` is your dropdown list. – heds1 May 31 '19 at 06:55
  • I am doing it using javaScript and JQuery as I am new in C#. Can you tell me how to do this in Javscript and JQuery – AnumShk May 31 '19 at 07:20

1 Answers1

2

This has resolved the issue and helped in completing the requirement

/* To Disable the first element in drop-down Accreditation */
 $("#ddlAccreditationId option[value='0']").attr("disabled", true);
AnumShk
  • 47
  • 10