【发布时间】:2011-01-13 19:49:45
【问题描述】:
因此,我在创建此方法并使其正常工作方面获得了很多帮助……但由于这是一个不同的人,我想我会提出另一个问题。
首先,我有一个 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);
}
【问题讨论】:
标签: c# .net asp.net-mvc-2 extension-methods html-helper