Programmermid Programmermid - 1 month ago 6x
AngularJS Question

How to pass a Value from MVC Controller to Angular View

I am using angularjs with MVC to check the write access of a folder for users. If the user has the write access then I want to show a div which has a link. I have a div in

and I have a method which checks for user's write access in MVC Controller called
. What will be the code for Angular Controller that I can use to pass value from MVC controller to Angularjs View?


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


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?


I might not be understanding the question exactly correctly, but I you case it might be best just to show or hide it using razor syntax, rather than exposing a variable and handling that in the JavaScript. If you're not returning a Model from your ASP.NET controller, then in your ASP.NET controller set the ViewBag variable like this:

ViewBag.DivPackerTemplateVisible = false;

And in your view:

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


You should also make sure that ViewBag.DivPackerTemplateVisible always has a value of true or false, possibly by declaring it to true at the top of your ASP.NET controller.