I have an object in a separate dll called “Program”, I added an extension method Called EncProgramId in the site project, so MyProgram.EncProgramId() returns a value, now I want a to use the Html.DropDownList to use that extension method for the values of the options: code:
This wont work: with the following error: DataBinding: ‘EncProgramId()’ is not a valid indexed expression.
@Html.DropDownList("ddlAcademicProgram", new SelectList(Model.AcademicPrograms, "EncProgramId()", "Name"), "Select all")
This does not work either.
@Html.DropDownList("ddlAcademicProgram", new SelectList(Model.AcademicPrograms, "EncProgramId", "Name"), "Select all")
any help would be greatly appreciated.
It looks like you have misunderstood the “Code” parameter of the SelectList constructor. This is the name of the Property from an AcademicProgram that you want to use for the value of the option in the drop down list.
Why can you not just specify the name of the property from an Academic program for the SelectList to use as it’s code value?