1

I have this strange situation where I have a WebMethod in WebService which needs to return a generic list and also need to have output Parameter attached to it.

And $.ajax({ }) need to call this webservice and get both return value and outparameter in .success().

Web Service is as below:

[WebMethod]
public static List < Category > GetAllCategory(out int TotalCountRecord) 
{
     List < Category > AllValues = new List < Category > ();
     //Some ADO.NET Code to Call Stored Procedure with output Value;
     SqlParameter OutParameter = new SqlParameter("@RecordCount", SqlDbType.Int);
     OutParameter.Direction = ParameterDirection.Output;
     cmd.ExecuteNonQuery();
     TotalCountRecord = (int)(OutParameter.Value);
     //Pls. Don't Mind these sequence of the code.
     return AllValues;
}

Now is there a Possible way for me to call these code for JQuery Ajax Like

var a = 0;
$.ajax({
   url: 'WebService1.asmx/GetAllCategory',
   method: 'post',
   dataType: 'json',
   data: JSON.stringify({TotalCountRecord: a}),
   contentType: 'application/json; charset=utf-8',
   success: function(data) {

    //Add data to Table
   //Show RecordCount at Footer of the Table
  }

Is these a way to address this situation?

1 Answer 1

1

i think its not possible.

you can return out parameter:

[WebMethod]
public static dynamic GetAllCategory(out int TotalCountRecord) 
{
 List < Category > AllValues = new List < Category > ();
 //Some ADO.NET Code to Call Stored Procedure with output Value;
 SqlParameter OutParameter = new SqlParameter("@RecordCount",SqlDbType.Int);
 OutParameter.Direction = ParameterDirection.Output;
 cmd.ExecuteNonQuery();
 TotalCountRecord = (int)(OutParameter.Value);
 //Pls. Don't Mind these sequence of the code.
 return new{AllValues,TotalCountRecord};
}

now in ajax:

success: function(data) {
    Add data.AllValues to Table
    Show data.TotalCountRecord at Footer of the Table
}
Sign up to request clarification or add additional context in comments.

1 Comment

..I made some silly mistake at my end but your suggestion worked!!!! Thank you so much.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.