2
I know this is very basic, but I’m starting now. I’m creating a neighborhood register, using Angularjs, my back-end is in C# with ASP.NET MVC. My method is called by view, but does not receive JSON:
This is my method of saving BairroController
:
//[HttpPost]
public dynamic save(string bairro)
{
string user = "100";
string pass = "a";
int idEmp = 1;
master = new ClassMaster();
BairroModel BairroModel = new BairroModel();
BairroDTO BairroDto = new BairroDTO();
return BairroDto.save(BairroModel, user, pass, master.contexto, BairroModel.t0020_id_empresa = idEmp);
}
This is Ajax save:
$scope.AddBairro = function (bairro) {
$http.post("http://localhost:23714/Bairro/save", bairro).success(function (data) {
//delete $scope.contatos;
$scope.contaroForm.$setPristine();
console.log(bairro);
});
};
Problems:
When you click save, my method is called, but the parameter receives
null
. Take the example here.The method is called twice and in the firefox console and it is possible to see what was sent, in this case, a
OPTIONS
and aPOST
(Why?), but in either case the method captures thejson
.In that link it is possible to see that the
json
was actually sent, it is also possible to see thePOST
and theOPTIONS
.In the Back-end, this part is commented, if "uncommented", the method is not called.
I changed the signature of my backend method, it was so public Dynamic save(neighborhood Bairromodel), I changed the type of the string neighborhood, for Bairromodel, it worked, how can I send more data beyond that contained in date. EX: besides the date, I want to send the number 1.
– alessandre martins