0

Is it possible to make a foreign key have the ReadOnly attribute in Dynamic Data or at least disable the dropdown of the foreign key field?

Let's say:

Class_Table | Student_Table
ClassID [PK]| StudentID [PK]
ClassName   | StudentName
            | ClassID [FK]

Those are the tables. Here is a sample code:

[ReadOnly(true)]
[ScaffoldColumn(true)]
public object ClassID { get; set; }

Because whenever I assign the ReadOnly attribute to a foreign key and try to insert a new record it gives me this HttpException:

"DataBinding: 'System.Web.DynamicData.Util.DictionaryCustomTypeDescriptor' does not contain a property with the name 'ClassID'."

Coolai
  • 151
  • 4
  • 18

1 Answers1

0

You can disable the dropdown filter control of a foreign key field by setting the DisplayAttribute correctly (AutoGenerateFilter)

[Display(Name = "Student", Order = 0, AutoGenerateFilter = false, AutoGenerateField = true)]        
    public object Student { get; set; }
Ash Machine
  • 9,601
  • 11
  • 45
  • 52