I'm trying to use AngularJS in my web application and I have a few questions on how to get the implementation of the onClick event for my upload button.
View:
<form action="" method="post" enctype="multipart/form-data">
<table style="margin-top:20px">
<tr>
<td><label for="file">Filename:</label></td>
<td><input type="file" name="file" id="file" accept=".csv" /></td>
<td><button type="submit" value="Upload" ng-click="uploadFile()" /></td>
</tr>
</table>
</form>
Controller (ASP.NET MVC):
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
//CSvReader reads in contents of the file and adds them to a list
//Stores the list in session
}
The part I'm stuck on is the implementation for the AngularJS script for the uploadFile() method.
I'm assuming on Click, I need to use an $http service that will post the data to my controller but I'm not sure how to do that. How do I pass in the necessary information from my view to my controller on the server side? Is there anything else I need to do in my angularJS script besides using that service?
I also mean to say is where would I put my onClick event inside my module code?
var myApp = angular
.module("myModule", [])
.controller("myController", function ($scope) {
$scope.uploadFile = function () {
// your upload logic here
var data = {
//file? What should data be?
};
$http
.post('Home/Index', data)
.success(function (data, status, headers, config) {
})
.errors(function (data, status, headers, config) {
});
};
});