0

我有一个扩展方法,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();
    }
}
4

1 回答 1

3

可能您的DropDownListExtensions类声明为嵌套在其他类中。将其移至命名空间级别。

于 2012-06-06T12:46:10.870 回答