I have looked around, but have not found anything (Angular post) that can actually make a successful call to a MVC Controller. I know there are a lot of Angular/.Net devs out there. Can I get some help?
Let's keep answers bare bones simple!!!
If I set a linebreak on the controller, I can see that this code is not actually hitting the controller.
HTML
<!-- I click this button --> <input type="button" value="click" onclick="postit()" />
Javascript/Angular Post
function postit() { $http({ method: 'POST', url: 'Home/Give/', data: { id: 4 } }).success(successFn).error(errorFn); } function successFn() { alert("success"); }
MVC C# Controller
[AcceptVerbs("OPTIONS")] public ActionResult Give(int id) { var response = "some response" + id.ToString(); return Json(new JavaScriptSerializer().Serialize(response)); }
[HttpPost]
to enable that action to receive posts. If that doesn't work, please tell us what is the response to the endpoint, you may do that by checking the Network tab on Chrome's developer tools.