-1
我對視此輸入:HTML輔助/文本框驗證
<%= Html.TextBoxCurrentDateWithoutPermission("EffectiveDate", Model.EffectiveDate.HasValue ? Model.EffectiveDate.Value.ToString("dd-MMM-yyyy") : "", new string[] { PERMISSIONS.hasICAdvanced }, new { @class = "economicTextBox", propertyName = "EffectiveDate", onchange = "parseAndSetDt(this); ", dataType = "Date" })%>
這是自定義HTML助手:
public static MvcHtmlString TextBoxCurrentDateWithoutPermission(
this HtmlHelper htmlHelper,
string name,
object value,
string[] permissions,
object htmlAttributes
)
{
foreach (string permission in permissions)
{
if (Chatham.Web.UI.Extranet.SessionManager.DisplayUser.IsInRole(permission))
{
// the user has the permission => render the textbox
return htmlHelper.TextBox(name, value, htmlAttributes);
}
}
// the user has no permission => render a readonly checkbox
var mergedHtmlAttributes = new RouteValueDictionary(htmlAttributes);
mergedHtmlAttributes["disabled"] = "disabled";
return htmlHelper.TextBox(name, value == "" ? DateTime.Now : value, mergedHtmlAttributes);
}
這是現在的工作方式,當用戶不有權通過,該框被禁用。
它需要的方式 - 如果用戶沒有通過權限,它需要啓用,但它可以接受的唯一日期是今天的日期和日期。
所以我需要jQuery驗證(或只是簡單的JS),該文本框以下情況下,頁面上:
如果文本框已啓用,用戶不具有的權限,允許用戶輸入僅當前日期或未來日期。