0
所以我有这个文本框的网页上:TextBoxFor扩展的HtmlHelper
<%= Html.TextBox("EffectiveDate", Model.EffectiveDate.HasValue ? Model.EffectiveDate.Value.ToString("dd-MMM-yyyy") : "", new { @class = "economicTextBox", propertyName = "EffectiveDate", onchange = "parseAndSetDt(this); ", dataType = "Date" })%>
它存储并显示使用日期选择器的日期。基本上,根据用户的权限,我希望这个文本框被禁用/启用。这很好,我可以做到这一点,但是,我想让文本框的值=当前日期,如果他们没有权限更改值。我可以用这个HTML扩展禁用它瓦特/权限:
public static MvcHtmlString TextBoxWithPermission(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, mergedHtmlAttributes);
}
但我怎么用当前日期填充它,如果它被禁用?