[英]Error passing array into extension 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);
}
這有點像問題:
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
}
您當前的代碼試圖在一個數組中傳遞一個權限,然后在另一個字符串中傳遞……而您大概打算在一個數組中傳遞兩個權限。
話雖這么說,這兩個權限在這里是相同的...看起來也是無意的。 您嘗試使用什么權限?
(出於可讀性考慮,只是出於興趣-不能添加using指令讓您僅引用PERMISSIONS.hasICAdvanced
嗎?)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.