"Cannot reference a type through an expression" 使用枚举值时

"Cannot reference a type through an expression" when using an enum value

我在尝试通过 html 标记设置用户控件初始化时收到错误 cannot reference a type through an expression。我可能正在寻找我在这里甚至无法实现的东西,但我能找到的唯一帮助与视频游戏和 MVC 有关,而这两者都不是。

基本上,我想通过 html 中的标记本身来初始化枚举类型的用户控件值。因此,当您声明用户控件时,它会设置所有需要的值。似乎只是抛出了那个错误,有什么见解吗?

标记

<uc:ucStateDropDownList id="UserControls_ucStateDropDownList" runat="server" StatesDisplayed="All"/>

背后的代码

public partial class UserControls_ucStateDropDownList : System.Web.UI.UserControl
{
    private StatesDisplayedInControl m_statesToDisplay;
    /// <summary>
    /// Existing options are as follows:
    ///     - UnitedStates (US states only)
    ///     - Canada (CDN states only)
    ///     - All (All states available)
    /// Default setting is 'All'.   
    /// </summary>
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public StatesDisplayedInControl StatesDisplayed 
    {
        get { return m_statesToDisplay; }
        set { m_statesToDisplay = value; }
    }
    public enum StatesDisplayedInControl : int
    {
        UnitedStates = 0,
        Canada = 1,
        All = 2
    }
}

当定义为 class 的一部分时,ASP.NET 似乎无法识别枚举。简单地在它自己的文件中定义它,或重新排列如下,让它工作:

public partial class UserControls_ucStateDropDownList : System.Web.UI.UserControl
{
    private StatesDisplayedInControl m_statesToDisplay;
    /// <summary>
    /// Existing options are as follows:
    ///     - UnitedStates (US states only)
    ///     - Canada (CDN states only)
    ///     - All (All states available)
    /// Default setting is 'All'.   
    /// </summary>
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public StatesDisplayedInControl StatesDisplayed 
    {
        get { return m_statesToDisplay; }
        set { m_statesToDisplay = value; }
    }
}

public enum StatesDisplayedInControl : int
{
    UnitedStates = 0,
    Canada = 1,
    All = 2
}