I am new to angular and ionic, so I started creating simple ionic application with AngularJS but I am facing a problem, I tried searching it on google but could not figure it out.
for testing I hard-corded parameters in angular controller. after click on submit button from ionic app, it hitting to the relevant action in API controller but data showing as null,
if anyone can help to figure this out it will be appreciate,
AngularJs Controller
$scope.savenewdansal= function(newDansal){
$http({
method : 'POST',
url : 'http://localhost:51079/api/Dansal/SaveNewDansal',
dataType: 'json',
data: JSON.stringify({"MainCategory": "category1","SubCategory": "subCateMy","District": "Central","City": "Colo","date": "2000-01-01T00:00:00","Time": "2001-01-01T00:00:00","Venue": "kurudnwa","contacts": "nocon"}),
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data) {
if (data.errors) {
console.log(data.errors.name)
} else {
console.log(data.message);
}
});
WebAPI Action
[HttpPost]
[ActionName("SaveNewDansal")]
public VM_NewDansal SaveDansal(VM_NewDansal newDansal)
{
return newDansal;
}
Model Class
public class VM_NewDansal
{
public string MainCategory { get; set; }
public string SubCategory { get; set; }
public string District { get; set; }
public string City { get; set; }
public string date { get; set; }
public string Time { get; set; }
public string Venue { get; set; }
public string contacts { get; set; }
}
both Ionic App and WebAPI Service running on localhost Thank you
$http.post(uri, data)and callbacks