使用枚举选择 MonoRail
我一直在关注本指南并且即将到来与我自己的混合物一起使用 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;
}
然而,尽管语法正确,但我收到以下错误:
节点 '$({ 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"})}
Where Roles was PropertyBag["Roles"] = typeof(角色);
I've been following this guide and coming up with my own concoction in order to use MonoRail's FormHelper.Select
that is generated from an enum. So here's the Brail syntax:
${FormHelper.Select("user.Role", ${LS.EnumToPairs(Roles)}, {"value":"First", "text":"Second"})}
"LS" is just my own helper, which I've defined as follows:
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;
}
Yet from this, despite being the correct syntax, I get the following error:
Node '$({ return Castle.MonoRail.Views.Brail.ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods.Invoke(self.GetParameter('LS'), 'EnumToPairs', (self.GetParameter('Roles'),)) })' has not been correctly
The source error doesn't help much unfortunately:
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 """
Any ideas what I'm doing wrong here?
EDIT
Based on the answer given below, the solution was finally this:
${FormHelper.Select("user.Role", LS.EnumToPairs(Roles), {"value":"First","text":"Second"})}
Where Roles was PropertyBag["Roles"] = typeof(Role);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: