2016-09-14 7 views
1

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

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

あなたは角使用している場合は、SampleView.Htmlディレクティブを作成し、あなたのMVC AccessPackerPlanTemplateメソッドを呼び出すことができるサービスを注入しなければなりません情報を取得したり、ルールルールとキャッシュの結果をすべてラップしたり、すべてのルールルールサービスを作成することができます。

ステップ1:DivPackerTemplate 指令ドキュメントをラップするディレクティブを作成 - >https://docs.angularjs.org/guide/directive

ステップ2:ルール・ロジックにあなたの呼び出しをラップ角度サービスを作成する(ルールがWEBAPIにする必要がありますが、あなたが定期的にMVCのアクションを使用することができます必要な場合) - >https://docs.angularjs.org/guide/services

次に、ルールサービスをディレクティブに挿入し、それを使用してテンプレートデータを取り込むことで、キャッシングはオプションです。あなたは「パス値の」ビューへのサーバーから、あなたの意見は、ビュー/ディレクティブに「値を引く」ために、角度のサービスを使用していない角度の世界では

私は、に沿って、角度専門家ではなく、何かないんだけどこれらの行は、角度サービスとしてのルールサービス実装($ rules)を省略して作成することはかなり簡単です。

angular.module('moduleA', []) 
.controller('SimpleDirectiveController', ['$rules','$scope',function($rules,$scope) { 
$scope.show = function() { 
    return $rules.yourmethodtogetrulesresult();//for this case return either 'hidden' or 'visible' 
}; }]) 
.directive('PackerTemplate', function() { 
    return { 
    template: function($scope) { 
     var templatevar = '<a ng-href="\\Samplefolder" visibility=\'[XX]\'>Edit Template</a>' 
     return templatevar.replace('[XX]',$scope.show()) 
     }  
    }; 
}); 
+0

あなたは私に私が使用できる任意のサンプルのための参照を与えることができますか? – Programmermid

0

あなたのMVCアプリケーションから、aspビューを返すことができます。ビュー内には、このようなあなたの角度のコントローラを使用することができます。

@model dynamic 

@{ 
    Layout = ""; 
} 

<div ng-controller="PackerListController as vm"> 
    <h1 class="page-header"> 
    <button ng-click="vm.editTemplate()">Edit Template</button> 
    </h1> 
</div> 

関連する問題