Gol Gh

Gol Gh

  • NA
  • 4
  • 656

Send Object of Objects From AngularJS to WebAPI

Dec 2 2017 2:59 PM
Hi
 
I'm trying to send an object to a WebAPI,
I checked out the perfect link below and performed all of that,
 
http://www.c-sharpcorner.com/UploadFile/cd7c2e/send-object-of-objects-from-angularjs-to-webapi/  
 
I send the data succesfully ,but i get "404 Not Found" error from my Ajax, it never stops on the point on my WebAPI page! that would be great if anybody can help me to fix this!! Thank you!!
 
here is my HTML page code:
 
<div ng-controller="TestCtrl">
<h3>
{{message}}
</h3>
<hr />
<div>
First Name:
<input type="text" placeholder="Enter your name" ng-model="details.firstName">
Last Name:
<input type="text" placeholder="Enter your last name" ng-model="details.lastName">
</div>
<hr />
<div>
Mobile Number:
<input type="text" placeholder="Enter your mobile number" ng-model="details.mobile">
EmailId:
<input type="text" placeholder="Enter your email id" ng-model="details.email">
</div>
<input type="button" ng-click="SendData(details)" value="Submit" />
<hr />
<h4 style="color:blueviolet">{{value}}</h4>
</div>
 
 
And here is my JS code:
 
'use strict'
app.controller('TestCtrl', function ($scope, $http) {
$scope.message = "Test";
//var TestCtrl = function ($scope, $http) {
alert(1)
$scope.SendData = function (Data) {
var GetAll = new Object();
GetAll.FirstName = Data.firstName;
GetAll.SecondName = Data.lastName;
GetAll.SecondGet = new Object();
GetAll.SecondGet.Mobile = Data.mobile;
GetAll.SecondGet.EmailId = Data.email;
$http({
url: "http://localhost:60102/NewRoute/firstCall",
dataType: 'json',
method: 'POST',
data: GetAll,
headers: {
"Content-Type": "application/json"
}
}).success(function (response) {
$scope.value = response;
})
.error(function (error) {
alert(error);
});
}
});
 
And here is WebAPI:
 
 
namespace EmployeeWebApliccatin
{
public class MyController : ApiController
{
// GET api/<controller>
[RoutePrefix("NewRoute")]
public class GetAll
{
public string FirstName { get; set; }
public string SecondName { get; set; }
public SecondGet SecondGet;
}
public class SecondGet
{
public string Mobile { get; set; }
public string EmailId { get; set; }
}
[Route("firstCall")]
[HttpPost]
public string firstCall(HttpRequestMessage request,
[FromBody] GetAll getAll)
{
return "Data Reached";
}
}
}
 
 
 
 
 
 
 
 
 
 
 

Answers (1)