После вызова WebMethod по запросу «POST» AngularJS, действие формы не следует функции в c # - PullRequest
0 голосов
/ 10 октября 2019

После вызова WebMethod по запросу AngularJS "POST", действие формы не следует функции в c #

<html>
<script type="text/javascript">

 var app = angular.module("ActionListApp", []);

 app.factory("Actions", function () {
     var serviceObj = {};
     serviceObj.AddAction = function ($http, $scope, $filter) {
         debugger;
         var req = {
             method: 'POST',
             url: 'ActionList.aspx/AddAction',
             data: {
                 strAction: $scope.mdlAction, intCategory: $scope.mdlCategory, intAsssignedTo: $scope.mdlAssignedTo

                 }
         }
         $http(req).success(function (data) {
             result = angular.fromJson(data.d);
             alert('success');
             //$scope.EventsList = result.Events;
             //$scope.Pages = result.Pages;
         }).error(function (data) {
             alert('error');
             console.log('error: Could not add the student');
         });

     };
     return serviceObj;
 });

 app.controller("ActionController", function ($http, $scope, $filter, 
 Actions) {

     $scope.ctrAddAction = function () {
         debugger;
         $scope.dtDueDate = 
    document.getElementById('dtDueDate').value;
         Actions.AddAction($http, $scope, $filter);
     };
 });
</script>
</html>

, это мой код aspx.cs:

  [WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string AddAction(String strAction, int intCategory, int 
   intAssignedTo)
{
try
{
    HttpContext.Current.Response.ContentType = "application/json; 
 charset=utf-8";
    dynamic json = new JObject();
    DataSet ds = new DataSet();
    ds=obj.AddAction(strAction, intCategory, intAssignedTo);
    json.action = (JArray)JToken.FromObject(ds.Tables[0]);
    return json.ToString();
}
catch (Exception ex)
{
    dynamic d = new JObject();
    d.status = "error";
    d.errormsg = ex.Message;
    d.stack = ex.StackTrace;
    return d.ToString();
}
}

В то время как в Debug (Browser) действие в форме выполняется до ActionList.aspx, а не ActionList.aspx / AddAction, поэтому мой веб-метод фактически не вызывается:

<form method="post" action="./ActionList.aspx" onsubmit="javascript:return 
 WebForm_OnSubmit();" id="form1" class="form-horizontal">
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...