我一直在遵循本指南并提出自己的混合物,以便使用FormHelper.Select
从枚举生成的 MonoRail。所以这里是 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;
}
然而,尽管语法正确,但我收到以下错误:
节点 '$({ 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"})}
角色在哪里PropertyBag["Roles"] = typeof(Role);