mark_norgate
asked on
ASP.NET Web API 2 with Angular woes
Hi there
This question relates to a problem I'm having with my (first) Web API 2 project. One of the actions on my controller is being hit successfully, but the values of the parameter passed in are all in their default states and do not correspond to the values sent from the Angular behaviour.
My controller looks like this:
My Web API 2 controller is successfully being hit, but the view model passed as a parameter is not being populated. It contains nulls for strings and falses for booleans.
My AngularJS call looks like this:
Fiddler looks like this:
I am using the default routing, like this:
Can anyone suggest what's going on?
Looking forward to your responses. Mark
This question relates to a problem I'm having with my (first) Web API 2 project. One of the actions on my controller is being hit successfully, but the values of the parameter passed in are all in their default states and do not correspond to the values sent from the Angular behaviour.
My controller looks like this:
[HttpPost]
public IEnumerable<string> Post(SearchParameters id)
{
return null;
}
public struct SearchParameters
{
string brokerIsUnallocated;
string brokerIncludeDeleted;
string businessType;
bool codeC;
bool codeD;
bool codeP;
bool codeS;
bool codeT;
bool codeX;
string companyName;
string contactName;
string country;
string customerId;
string department;
string selectedBroker;
string town;
}
My Web API 2 controller is successfully being hit, but the view model passed as a parameter is not being populated. It contains nulls for strings and falses for booleans.
My AngularJS call looks like this:
$scope.search = function () {
var id = { id : {
selectedBroker: typeof ($scope.selectedBroker) === 'undefined' ? 0 : $scope.selectedBroker.userIdField,
brokerIsUnallocated: $scope.brokerIsUnallocated || false,
brokerIncludeDeleted: $scope.brokerIncludeDeleted || false,
customerId: $scope.customerCustomerId || 0,
businessType: $scope.customerBusinessType || "",
companyName: $scope.customerCompanyName || "",
town: $scope.customerTown || "",
department: $scope.selectedDepartment || 0,
contactName: $scope.customerContactName || "",
country: $scope.selectedCountry || 0,
codeP: $scope.codeP || false,
codeC: $scope.codeC || false,
codeT: $scope.codeT || false,
codeS: $scope.codeS || false,
codeX: $scope.codeX || false,
codeD: $scope.codeD || false
}
}
$http({
method: 'POST',
url: '/api/customer',
data: id
});
}
Fiddler looks like this:
I am using the default routing, like this:
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Can anyone suggest what's going on?
Looking forward to your responses. Mark
ASKER
I did try that today, but it had no effect.
Mark
Mark
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok thanks, I'll give that a shot when I get back to work on Monday.
M
M
ASKER
Yep, that fixed it. Thank you very much!
Mark
Mark
Open in new window