我有DropDownList
的扩展方法,它会在关键字Extension method can only be declared in non-generic, non-nested static classes
上投放this
。我不太清楚为什么,因为我在DropDownList
public static class DropDownListExtensions {
public static void populateDropDownList(this DropDownList source, Action delegateAction) {
source.DataValueField = "Key";
source.DataTextField = "Value";
source.DataSource = delegateAction;
source.DataBind();
}
}
答案 0 :(得分:3)
可能您的DropDownListExtensions
类声明为嵌套了其他类。将其移至命名空间级别。