I need to perform a file upload and send form data to WebApi Controller using AngularJS (also for IE8).
I have my form defined as
<form name="sendForm" ng-submit="submitForm()">
<input type="text" name="fname" placeholder="First name" ng-model="form.firstname">
<br>
<input type="text" name="lname" placeholder="Last name" ng-model="form.lastname">
<br>
<input type="text" name="email" placeholder="Email" ng-model="form.email">
<br>
<input type="file" ng-model="form.file_idea" id="file_profile"><br />
<br>
<input type="submit" value="Submit">
</form>
My Angular controller method is:
$scope.submitForm = function ()
{
formData = $scope.form;
var formObjectForWebApi =
{
Username: $scope.form.firstname,
Lastname: $scope.form.lastname,
Email: $scope.form.email,
};
$masterContext.SendForm(formObjectForWebApi).then(function (res)
{
});
}
My Master Context is defined as
var MasterContext = angular.module("MasterContext", []); MasterContext.service("MasterContextService", ["$resource",
function ($resource)
{
var service = {};
service.SendForm= function (form)
{
var webapiresource = $resource('/api/formcontroller/sendform');
return webapiresource.save(form).$promise.
then(function (res)
{
return res;
},
function error(res)
{
return res;
});
};
return service;
}]);
My Web Api receive the data as
[Route("api/formcontroller/sendform")]
[HttpPost]
public IHttpActionResult SendForm(MyForm form)
{
.
.
.
.
.
If i check the current request i am unable to find the file that the user wants to upload. How can i solve my situation?