Angular post for ASP.MVC

Asked

Viewed 90 times

0

I need to do a POST after a button click, so that this POST activates a method in a MVC controller, was testing as follows:

[HttpPost]
public void GerarPDF()
{
    string teste = "teste";
}

The name of the Controller is Itemcontroller, already on the button I put the ng-click with the angle function:

<button type="submit" ng-click="exibiritem()" class="navbar-btn btn btn-modal"  style="margin-right:0px;" id="btnExibir">
  <center>Exibir</center>
</button>

And in the angular controller:

function exibiritem(){
    $http({
        url: "/item/GerarPDF",
        method: "POST"
    )};
}

I’m just not getting the function in the MVC controller executed. If anyone can help me, I would be very grateful, because my knowledge in angular is still very basic.

  • Starting from the beginning, the function exibirItem() is being called at the click of the button?

  • this ng-click="display()"

  • Maybe it’ll help. Post example: http://stackoverflow.com/questions/32026618/angular-http-post-with-asp-net-mvc Get example: http://stackoverflow.com/questions/37844205/read-the-returned-json-datafrom-mvc-controller-angular-controller

1 answer

0


 public JsonResult GerarPDF(Objeto objeto) {
    return Json(ObjetoRetorno, JsonRequestBehavior.AllowGet);
   }



$scope.exibiritem= function (objetoEntrada) {
    $http.post('Area/Controller/Action', { objeto: objetoEntrada}).success(function (retorno) {
       $scope.retorno = retorno;
    });
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.