0
所以,我有一個擴展方法,用於使用戶在權限的陣列這樣傳遞Html.CheckBoxFor()方法:HTML輔助擴展方法Html.Textbox
<%= Html.CheckBoxForWithPermission(m => m.Current, new string[] { PERMISSIONS.hasICAdvanced }, new { @class = "economicTextBox", propertyName = "Current", onchange = "UseCurrent();UpdateField(this);" })%>
的方法,看起來像這樣的:
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);
}
基本上,我想創建除了一個Html.TextBox方法完全一樣的事情,我們目前這樣調用:
<%= Html.TextBox("RateTimeStamp", Model.RateTimeStamp.HasValue ? Model.RateTimeStamp.Value.ToString("dd-MMM-yyyy") : "", new { @class = "economicTextBox", propertyName = "RateTimeStamp", onchange = "parseAndSetDt(this);", dataType = "Date" })%>
由於這個幫手有點不同,我不確定如何格式化該方法。
任何幫助將不勝感激。謝謝!