2010-08-19 83 views
0

我一直在關注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);

回答

0

試試這個:

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

這是非常接近,但它不會讓我做'typeof (角色)'(這是實際的枚舉類型)或'typeof(角色)'如果'角色'在PropertyBag中,就像我在代碼中顯示的那樣。相反,我做了'LS.EnumToPairs(Roles)',那裏有'PropertyBag [「Roles」] = typeof(Role);' - 不要問我爲什麼它不會讓我,因爲角色甚至不在命名空間。儘管你的想法導致瞭解決方案。 – Kezzer 2010-08-19 14:05:20

+0

@Kezzer:對,你必須把'角色'的完整命名空間,並確保有正確的程序集引用。 – 2010-08-19 14:14:59

+0

事實上,「角色」從來都不在名稱空間中,所以我不確定在這種情況下會發生什麼。我確實在導入時嘗試了'Project.Role',沒有任何運氣。不確定那裏發生了什麼。 – Kezzer 2010-08-19 14:32:45