This is a migrated thread and some comments may be shown as answers.

Passing parameters to webmethod

8 Answers 562 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 15 Jun 2012, 01:09 PM
I am new to using the Kendo UI suite of products, and am going crazy trying to pass  a parameter to my c# webmethod.  I have everything up and running when I don't use the paramter, and data pulls, saves, etc. just fine.  But, when I try to pass the parameter, I get the error: 

Invalid web service call, missing value for parameter: \u0027ageGroupID\u0027.

The relevant code is below.  Note that this is just the most recent iteration of the code, as I have tried a lot of different ways to get this working, based on the information found in this forum, and elsewhere.

I have set the variable many different ways.  The most recent was to pretty much set the json, but I have tried just setting the value I am passing, then setting the full json in the data: statement.

var miniMiteAgeID = { 'ageGroupID': "11" };

Here is my read statement:

read: {
                    url: "AssociationStats.aspx/getPlayerInfo", //specify the URL which data should return the records. This is the Read method of the Products.asmx service.
                    contentType: "application/json; charset=utf-8", // tells the web method to serialize JSON
                    dataType: "json",
                    data: JSON.stringify(miniMiteAgeID),
                    type: "POST" //use HTTP POST request as the default GET is not allowed for web methods
 
                },

My webmethod is below...

[WebMethod]
public static IEnumerable<teamPlayers> getPlayerInfo(string ageGroupID)
{
 
  //Do a bunch of stuff
 
}

Any help or suggestions you might have would be greatly appreciated.  I am at my wits end.

Thanks,

Scott

8 Answers, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 15 Jun 2012, 01:13 PM
Just for added info:

I have tried double quotes around ageGroupID and no quotes.  Same goes for 11.  I put a breakpoint at the beginning of my [webmethod] and it is not getting triggered, so the problem is happening as the json is being posted to the webmethod, or when the webmethod is trying to receive the post from the javascript...as the error indicates.
0
Scott
Top achievements
Rank 1
answered on 15 Jun 2012, 02:32 PM
More info...I have found several examples of people doing the same thing that I am, and have tried all of their suggestions.  My confusion is that if I even pass a straight json string to my webmethod, I am still getting the same error.

data: "{'ageGroupID':'11'}",

Just seems like this should work, and nothing I do triggers even gets to the method where my breakpoint exists.

0
Scott
Top achievements
Rank 1
answered on 15 Jun 2012, 02:46 PM
I figure I will just keep posting as I investigate further, in case it helps point someone in the right direction to get this working.

Currently, I am trying it the following way, per another example that is almost identical to mine.  The webmethod is the same, and accepts ageGroupID as a string parameter. 
[WebMethod]
public static IEnumerable<teamPlayers> getPlayerInfo(string ageGroupID)

When I run fiddler, I don't see that anything at all is being passed to the webmethod.  (unless I am reading the Fiddler results incorrectly) 
POST /MemberPages/Pages/AssociationStats.aspx/getPlayerInfo HTTP/1.1
Host: localhost:58034
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/json; charset=utf-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:58034/MemberPages/Pages/AssociationStats.aspx
Cookie: __utma=111872281.1183024001.1319639472.1339695715.1339765348.233; __utmz=111872281.1319639472.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); SiteSettings=Username=dsyhcoach1; .ASPXAUTH=BEEAD6096F1AD7C1DB9F1A05786A54733C212D05B79F9F7C1A437A72EFDFA21D3A70C88FB616736836FE578BD14095511C302C59B6DDFC3C9717672B24F1A769802DD8C0A9457E5D8AFBEEA89CAF55EB1CE36B2493A6280F3AF1B4C96216C71F669CECBA0EB62D42504AADB9A95F6DA7C452F6E396202574116982E6318CBF48A453B6793C25D1B0768F73CA8E283F1C; __utmb=111872281.19.10.1339765348; ASP.NET_SessionId=evz2ffwdjn5ehn5ubpfoz4j3; __utmc=111872281
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 0


var miniMiteAgeID = { 'ageGroupID': '11' };
 
read: {
                    url: "AssociationStats.aspx/getPlayerInfo", //specify the URL which data should return the records. This is the Read method of the Products.asmx service.
                    contentType: "application/json; charset=utf-8", // tells the web method to serialize JSON
                    dataType: "json",
                    data: JSON.stringify(miniMiteAgeID),
                    type: "POST" //use HTTP POST request as the default GET is not allowed for web methods
                },
0
Scott
Top achievements
Rank 1
answered on 15 Jun 2012, 03:36 PM
After further inspection, I can say definitively that no json, or data at all is being passed in my POST.  I have no idea why this is the case.  Obviously, I am missing something simple, but I don't see what it could be...any ideas????
0
Jerry T.
Top achievements
Rank 1
answered on 15 Jun 2012, 07:34 PM
Scott,

You should be using a parameterMap. Try something like this:

//Declaring object for passing parameters
 
options: {
    Id: null
}
 
 
//Defining the data source
 
this.ItemsDataSource = new kendo.data.DataSource({
    transport: {
        create: {
            type: "POST",
            url: "../Services/Js/Service_Js.svc/InsertItem",
            contentType: "application/json; charset=utf-8",
            dataType: "json"
        },
        read: {
            type: "POST",
            url: "../Services/Js/Service_Js.svc/GetItems",
            contentType: "application/json; charset=utf-8",
            dataType: "json"
        },
        update: {
            type: "POST",
            url: "../Services/Js/Service_Js.svc/UpdateItem",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            complete: function(e) {
                me.readItems();
            }
        },
        destroy: {
            type: "POST",
            url: "../Services/Js/Service_Js.svc/DeleteItem",
            contentType: "application/json; charset=utf-8",
            complete: function(e) {
                me.readItems();
            }
        },
        parameterMap: function(options, operation) {
            switch (operation) {
                case "read":
                    return JSON.stringify(options);
                    break;
 
                case "destroy":
                    return JSON.stringify(options);
                    break;
 
                case "create":
                case "update":
                    return JSON.stringify(options);
                    break;
            }
        }
    },
    schema: {
        data: "d",
        model: {
            id: "Id",
            fields: {
                Id: { editable: false, nullable: false },
                Category: { editable: true, type: "string" },
                Item: { editable: true, type: "string" },
                CostPerUnit: { editable: true, type: "decimal" },
                Units: { editable: true, type: "number" },
                Cost: { editable: true, type: "number" }
            }
        }
    }
});
 
 
// read data into the data source from a web service
 
this.ItemsDataSource.read({
    Id: 1   //Id value of 1...here's where you'd pass in your miniMiteAgeID
});


Jerry
0
Scott
Top achievements
Rank 1
answered on 18 Jun 2012, 04:19 PM
Thanks a ton, Jerry.  I had the parameter map in there, but really didn't understand its purpose.  Your post made the light turn on, and I saw that I wasn't passing the parameters...that had been driving me crazy. 

I did have one more question that I was hoping someone could give me direction on.  Basically, I have 14 grids on a page that all derive from a single datasource.  It looks like this:

Age Group 1
   -  players
   -  goalies
Age Group 2
   -  players
   -  goalies
Etc.

So, I am using tabstrips for the players and goalies in each age group using a filter in the datasource.  And, I am passing the ageGroupID to my webmethod to get just those in that age group.  BUT, this is causing me to have 14 datasources, which can be a bit difficult to maintain.  I am replacing asp.net datalists, and I was able to easily do the filtering in the code behind, but I can't figure out the best strategy for achieving the above, with less than 14 datasources.  For other reasons, it would make sense for me to have a goalie datasource, and a player datasource, then just filter somehow by ageGroupID on each grid, but I can't figure out how to do this.

I might just be missing something obvious, but I am a bit new to javascript/Kendo.

Thanks again for the help.

Scott

Does anyone have an idea of a strategy that would work in this instance?
0
Scott
Top achievements
Rank 1
answered on 18 Jun 2012, 04:22 PM
FYI, I am currently using tabstrips to provide the player and goalie info in two separate grids within each age group.
0
Scott
Top achievements
Rank 1
answered on 20 Jun 2012, 01:12 PM
I guess no one has any ideas...maybe the cumbersome way I am doing it is the only way to do it.

Basically, I have a datasource for every grid, and each grid is really two grids, which utilize tabstrips to hide/show.  So, I have 14 datasources on the page.  I can now pass parameters to the webmethod, in order to limit the amount of data for each datasource, but it still seems like I should be able to create a datasource with the remote data, then derive/filter my other datasources from that datasource.
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Jerry T.
Top achievements
Rank 1
Share this question
or