2016-09-14 14 views
1

私はAsp.net MVCでangularjsを使用して、ユーザーのフォルダの書き込みアクセスをチェックしています。ユーザーに書き込みアクセス権がある場合は、リンクを持つdivを表示したいと思います。 SampleView.Htmlにdivがあり、MVCコントローラでユーザの書き込みアクセスを確認するメソッドがReportController.csとなっています。 MVCコントローラからAngularjsビューに値を渡すために使用できるAngular Controllerのコードは何ですか?MVCコントローラから角度ビューに値を渡す方法

SampleView.html:

<div id="DivPackerTemplate" class="cp-btn cp-btn-primary pull-right"> 
<a ng-href="\\Samplefolder" >Edit Template</a></div> 

ReportController.cs:

public void AccessPackerPlanTemplate(string folderPath) 
     {   
      string path = @"\\sample"; 
       string NtAccountName = @"sampleuser"; 

       DirectoryInfo di = new DirectoryInfo(path); 
       DirectorySecurity acl = di.GetAccessControl(AccessControlSections.All); 
       AuthorizationRuleCollection rules = acl.GetAccessRules(true, true, typeof(NTAccount)); 

       //Go through the rules returned from the DirectorySecurity 
       foreach (AuthorizationRule rule in rules) 
       { 
        //If we find one that matches the identity we are looking for 
        if (rule.IdentityReference.Value.Equals(NtAccountName, StringComparison.CurrentCultureIgnoreCase)) 
        { 
         //Cast to a FileSystemAccessRule to check for access rights 
         if ((((FileSystemAccessRule)rule).FileSystemRights & FileSystemRights.WriteData) > 0) 
         { 
          //Show the link 
          { 
           DivPackerTemplate.Visible = false; \\This is not working is there a alternative for this? 
          } 
         } 
        } 
       } 
+0

divにng-showを使用 – holtc

+0

divを非表示にするには、角型コントローラに何らかの値を送る必要があります。 HTMLページにはどのようなデータが表示されますか? divが隠されるべきかどうかのブールとして使用できるフィールドはありますか? –

+0

@RaniRadcliff HTMLページは、誰もがフォルダへの書き込みアクセス権を持っている特定のユーザーだけにフォルダのリンクを表示したくないホームページのようなものです。このメソッドをVoidからboolに変換できます。 – Programmermid

答えて

0

私は正確に正しく質問を理解していない可能性がありますが、私はあなたはそれがちょうどそれを表示または非表示にすることが最善であるかもしれないケース変数を公開してJavaScriptで処理するのではなく、かみそりの構文を使用します。

ViewBag.DivPackerTemplateVisible = false; 

そして、あなたのビューで:

@if(ViewBag.DivPackerTemplateVisible) { 
    <div id="DivPackerTemplate" class="cp-btn cp-btn-primary pull-right"><a ng-href="\\Samplefolder" >Edit Template</a></div> 

} 

あなたがすべきあなたはASP.NETコントローラからモデルを返していない場合は、お使いのASP.NETコントローラでは、このようなViewBag変数を設定また、ViewBag.DivPackerTemplateVisibleが常にtrueまたはfalseの値を持っていることを確認してください。おそらく、ASP.NETコントローラの上部でtrueに宣言してください。

関連する問題