2011-02-03 24 views
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); 
} 

しかし、無効になっている場合、現在の日付でどのように記入しますか?

答えて

1

もし私がこの権利を読んでいるのであれば、TextBoxWithPermissionに渡される値ではなく、許可なしの場合の値として現在の日付を渡したいだけですか?

// the user has no permission => render a readonly checkbox 
var mergedHtmlAttributes = new RouteValueDictionary(htmlAttributes); 
mergedHtmlAttributes["disabled"] = "disabled"; 
return htmlHelper.TextBox(name, DateTime.Now, mergedHtmlAttributes);