Search code examples
c#asp.netdeploymentsql-server-2012-express

Unknown web method Delete_Local_ABC. Parameter name: methodName in ASP.NET app


I have been getting this error on my following code, which basically initiates the POST request as ABC.ascx

var ABCid = $(aTag).data('id');
        $.ajax({
            type: "POST",
            url: "WebMethods.aspx/Delete_Local_ABC",
            data: "{'id':'" + ABCid + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: successdelete_ABC,
            error: Errordelete_ABC
        });
    }

WebMethods.aspx.cs

[WebMethod]
public static int Delete_Local_ABC(string id)
{
    ABC objABC = new ABC();
    objABC.ABC_ID = Convert.ToInt32(id);
    // call business manager
    try
    {
        BusinessManager businessManager = new BusinessManager();
        businessManager.ManageABC(objABC, OperationTypes.Validate);
        return 1;
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

and I am calling following method in BusinessManager.cs

....
case OperationTypes.Validate: 
                    obj.deleteLocalABC();
                    break;
...

and ABC.cs

public bool deleteLocalABC()
        {
            string query = "DELETE FROM TBL_ABC WHERE ABC_ID ='" + this.ABC_ID + "'";
            _dbManager.executeQuery(query);

            return true;
        }

I have tried all the solutions available online but nothing is working. This code works perfectly with Visual Studio but not on main deployment.


Solution

  • Use

    [WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
    

    instead of just [WebMethod]. I hope your method work fine after that addition.