I have an actionlink which triggers a function in the view controller, the function moves a file from one folder to an "archive" folder, so it doesn't return anything. However when the button is clicked the function fires and the correct file is moved but the view changes to "/functionName + variables", I need the page to stay the same and for just the function to run. Ideally not with a work around of having the page refresh/re-direct back to itself.
The button is in an ng-repeat as the files can change, there is also a button to download the file this fires and the file is downloaded, no view change etc occurs.
<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 construct the actionlink URLs then apply them to each button using data-ng-href
The function is a void as it doesn't return anything unlike the file download function which is of 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've tried adding "id="something" to the {} containing the action variables and then adding the following to the bottom of the page (The below was taken from another similar question on here)
<script>
$("#something").click(function (e) {
e.preventDefault();
$.ajax({
url: $(this).attr("href"),
success: function () {
alert("clicked");
}
});
});
</script>
But this results in nothing happening
EDIT: I have also also tried the js/ajax id on tag and the within with same results.