Whenever I click on an actionlink button, it triggers a function in the view controller that moves a file from one folder to an "archive" folder. The issue is that even though the file gets moved correctly, the view changes to "/functionName + variables". I want the page to stay the same and only have the function executed without any redirection or page refresh.
The buttons are generated within an ng-repeat loop as the files can change. There is also another button to download the file, which works fine without causing any view changes.
<div ng-repeat="file in toFileList">
@{
var toURL = Url.Action("DownloadFile", "Home", new { ToFrom = "to", FileName = "{{toFileList[$index][0]}}"});
toURL = HttpUtility.UrlDecode(toURL);
}
@{
var toArchiveURL = Url.Action("ArchiveFile", "Home", new { ToFrom = "to", FileName = "{{toFileList[$index][0]}}" });
toArchiveURL = HttpUtility.UrlDecode(toArchiveURL);
}
<a style="text-decoration: none;" data-ng-href="@toURL">
<span class="glyphicon glyphicon-download-alt"></span>
</a>
<a style="text-decoration: none;" data-ng-href="@toArchiveURL">
<span class="glyphicon glyphicon-eye-open"></span>
</a>
</div>
I define the actionlink URLs and assign them to each button using data-ng-href
The ArchiveFile function does not return anything, unlike the DownloadFile function which returns an ActionResult type.
public void ArchiveFile(string ToFrom, string FileName)
{
string path = BaseFolder + client + @"\" + ToFrom + @"\" + FileName;
string destinationPath = BaseFolder + client + @"\" + ToFrom + @"\Archive\" + FileName;
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
System.IO.File.Move(path, destinationPath);
}
I have attempted various solutions like assigning an ID to the action variables and trying to use AJAX functionality with jQuery to prevent default behavior upon button click, but so far nothing has worked.