Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
851 views
in Technique[技术] by (71.8m points)

MonoRail Select Using Enum

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);

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...