2011-01-13 17 views
0

所以我在這裏創建這個方法並使其工作時有很多幫助......但是因爲這是一個不同的人,所以我想我會提出另一個問題。將數組傳遞給擴展HTML Helper時出錯

首先,我有一個HTML Helper擴展方法,它通過傳遞額外的字符串來確定我在擴展中檢查的權限。我現在想在字符串(權限)的數組來傳遞,並通過他們的方法循環,​​但我得到這個錯誤:

CS1501:沒有重載方法「CheckBoxForWithPermission」需要4個參數

這裏是助手的電話:

<%= Html.CheckBoxForWithPermission(m => m.Current, new string[] { Chatham.Web.Business.Definitions.Constants.PERMISSIONS.hasICAdvanced }, Chatham.Web.Business.Definitions.Constants.PERMISSIONS.hasICAdvanced, new { @class = "economicTextBox", propertyName = "Current", onchange = "UseCurrent();UpdateField(this);" })%> 

,這裏是實際的方法:

// CHECKBOX WITH PERMISSIONS 
     // WITHOUT -- READONLY 
     public static MvcHtmlString CheckBoxForWithPermission<TModel>(
                  this HtmlHelper<TModel> htmlHelper, 
                  Expression<Func<TModel, bool>> expression, 
                  string[] permissions, 
                  object htmlAttributes 
                 ) 
     { 
      foreach (string permission in permissions) 
      { 
       if (Chatham.Web.UI.Extranet.SessionManager.PhysicalUser.IsInRole(permission)) 
       { 
        // the user has the permission => render the checkbox 
        return htmlHelper.CheckBoxFor(expression, htmlAttributes); 
       } 
      } 
      // the user has no permission => render a readonly checkbox 
      var mergedHtmlAttributes = new RouteValueDictionary(htmlAttributes); 
      mergedHtmlAttributes["disabled"] = "disabled"; 
      return htmlHelper.CheckBoxFor(expression, mergedHtmlAttributes); 
     } 

回答

1

該位看起來像問題:

new string[] { 
    Chatham.Web.Business.Definitions.Constants.PERMISSIONS.hasICAdvanced 
}, 
Chatham.Web.Business.Definitions.Constants.PERMISSIONS.hasICAdvanced 

我認爲應該是:

new string[] { 
    Chatham.Web.Business.Definitions.Constants.PERMISSIONS.hasICAdvanced,  
    Chatham.Web.Business.Definitions.Constants.PERMISSIONS.hasICAdvanced 
} 

您當前的代碼試圖在數組中傳遞一個許可,然後又單串......而想必你意味着通過在一個擁有兩個權限的數組。

話雖如此,這兩個權限在這裏是一樣的......看起來也是無意的。 想要使用什麼樣的權限?

(只是出於興趣,爲便於閱讀的緣故 - 你不能添加使用的指令,讓您只需參考PERMISSIONS.hasICAdvanced?)

+0

我這樣一個白癡。今天我的頭不在遊戲中。謝謝。 – slandau 2011-01-13 19:55:28

相關問題