MonoRail选择使用枚举

时间:2010-08-19 07:20:32

标签: castle-monorail

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

${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;
}

然而,由于这是正确的语法,我得到以下错误:

  

Node'$({return Castle.MonoRail.Views.Brail.ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods.Invoke(self.GetParameter('LS'),'EnumToPairs',(self.GetParameter('Roles'),))})'has不正确

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

  

第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"})}

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

的地方

1 个答案:

答案 0 :(得分:0)

试试这个:

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