Reputation: 598
I am using angularjs with Asp.net 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 SampleView.Html
and I have a method which checks for user's write access in MVC Controller called ReportController.cs
. What will be the code for Angular Controller that I can use to pass value from MVC controller to Angularjs View?
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?
}
}
}
}
Upvotes: 1
Views: 1173
Reputation: 1601
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.
Upvotes: 0