【问题标题】:MonoRail Select Using EnumMonoRail 使用枚举选择
【发布时间】:2010-08-19 07:20:31
【问题描述】:

我一直在关注 this guide 并想出我自己的混合物,以便使用从枚举生成的 MonoRail 的 FormHelper.Select。所以这里是盲文语法:

${FormHelper.Select("user.Role", ${LS.EnumToPairs(Roles)}, {"value":"First", "text":"Second"})}

“LS”只是我自己的助手,我定义如下:

public IEnumerable<Pair<int, string>> EnumToPairs(Type e)
{
    IList<Pair<int, string>> pairs = new List<Pair<int, string>>();

    foreach (int val in Enum.GetValues(e))
        pairs.Add(new Pair<int, string>(val, Enum.GetName(e, val)));

    return pairs;
}

然而,尽管语法正确,但我收到以下错误:

节点 '$({ return Castle.MonoRail.Views.Brail.ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods.Invoke(self.GetParameter('LS'), 'EnumToPairs', (self.GetParameter('Roles'),)) })' 有没有正确

不幸的是,源错误并没有多大帮助:

第 15 行:输出 FormHelper.TextField("user.Role", {"class":"text-input full-width"}) 第 16 行:输出 """ 第 17 行:“” 第 18 行:输出 FormHelper.Select("user.Role", ${LS.EnumToPairs(Roles)}, {"value":"First", "text":"Second"}) 第 19 行:输出 """

有什么想法我在这里做错了吗?

编辑

根据下面给出的答案,最终解决方案是:

${FormHelper.Select("user.Role", LS.EnumToPairs(Roles), {"value":"First","text":"Second"})}

Roles 是 PropertyBag["Roles"] = typeof(Role);

【问题讨论】:

    标签: castle-monorail


    【解决方案1】:

    试试这个:

    ${FormHelper.Select("user.Role", LS.EnumToPairs(typeof(Roles)), {"value":"First", "text":"Second"})}
    

    【讨论】:

    • 这非常接近,但它不会让我这样做 typeof(Role) (这是实际的枚举类型)或 typeof(Roles) 如果 Roles 在 PropertyBag 中,正如我在我的代码中显示的那样.相反,我做了LS.EnumToPairs(Roles) 那里有PropertyBag["Roles"] = typeof(Role); - 不要问我为什么它不让我,因为角色甚至不在命名空间中。不过,您的想法导致了解决方案。
    • @Kezzer:对,你必须把 Role 的完整命名空间放入并确保它具有正确的程序集引用。
    • 确实,但Role 从未在命名空间中,所以我不确定在这种情况下会发生什么。我确实在导入时尝试了Project.Role,但没有任何运气。不确定那里到底发生了什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 2018-10-03
    相关资源
    最近更新 更多