我一直在关注this guide并提出我自己的混合,以便使用从枚举生成的MonoRail的FormHelper.Select
。因此,这里的盲文语法:MonoRail使用枚举选择
${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 not been correctly
源错误没有太大的帮助不幸的是:
Line 15: output FormHelper.TextField("user.Role", {"class":"text-input full-width"}) Line 16: output """ Line 17: """ Line 18: output FormHelper.Select("user.Role", ${LS.EnumToPairs(Roles)}, {"value":"First", "text":"Second"}) Line 19: output """
任何想法我在这里做错了吗?
编辑
基于下面给出了答案,该方案最终这样的:
${FormHelper.Select("user.Role", LS.EnumToPairs(Roles), {"value":"First","text":"Second"})}
如果角色是PropertyBag["Roles"] = typeof(Role);
这是非常接近,但它不会让我做'typeof (角色)'(这是实际的枚举类型)或'typeof(角色)'如果'角色'在PropertyBag中,就像我在代码中显示的那样。相反,我做了'LS.EnumToPairs(Roles)',那里有'PropertyBag [“Roles”] = typeof(Role);' - 不要问我为什么它不会让我,因为角色甚至不在命名空间。尽管你的想法导致了解决方案。 – Kezzer 2010-08-19 14:05:20
@Kezzer:对,你必须把'角色'的完整命名空间,并确保有正确的程序集引用。 – 2010-08-19 14:14:59
事实上,“角色”从来都不在名称空间中,所以我不确定在这种情况下会发生什么。我确实在导入时尝试了'Project.Role',没有任何运气。不确定那里发生了什么。 – Kezzer 2010-08-19 14:32:45