Basically, my question is: how do I specify optional parameters to a WebMethod when providing JSON data?
I know I can reduce the parameters down to just the required values, and then use HttpContext.Request.Params to read the values of optional paramaters, but I would have thought the way I have tried here should have worked.
EDIT
The XMLHttpRequest.responseText value for the error is:
Invalid JSON primitive: staffcode.
This is throwing me even more off the scent of the problem :(
I'm doing an jQuery AJAX POST call to a webmethod, which is working fine. If I'm passing data from the AJAX call, I normally get the data in the webmethod via webmethod parameters.
JavaScript Code: $.ajax({"dataType": "json","contentType": "application/json","type": "POST","url": "Default.aspx/GetStuff","data": JSON.stringify({"a":"data1","b":2}),"success": function (msg) {Â Â console.log(msg.d);}}); C# Code: [WebMethod]public static object GetStuff(string a, int b){Â }
Is there any way I can get the data as a Dictionary or some other object, instead of having to put in individual parameters to the GetStuff() web method for each data param? It's a POST request so nothing is in Request.QueryString, and Request.Params/Request.Form doesn't contain it either.
I am using AJAX Cascading dropdown extender,and i have made a running dummy example.Using web service second dropdown is filled based on the selection of first drop down. But actual query that should fill second drop down have some more constraints in 'where' clause of the sql query, and that's value is too dynamic that (i cannot assume its value to be static). So i need that that variable's value in my web method too.
I want to send single json object with nested arrays through jquery ajax method.
In Code
In jquery ajax i am passing LeaveRuleMaster a single json object which holds some properties (Leavetypeid, Leavename, Leavestatus and nested array LeaveRulespecific.
In vb.net code i can receive the value of properties(Leavetypeid,Leavename,Leavestatus)
but i am receiving the LeaveRuleSpecific as nothing.
Based on the following link i tried this [URL] .....
I am using jquery ajax method on my aspx page,which will invoke the webmethod in the code behind.Currently the webmethod takes a couple of parameters like firstname,lastname,address etc which I am passing from jquery ajax method using
now my requirement has been changed such that,the number and type of parameters that are going to be passed is not fixed for ex.parameter combination can be something like fname,city or fname,city or city,lname or fname,lname,city or something else.So the webmethod should be such that it should accept any number parameters.I thought of using arrays to do so, as described here.
But I do not understand how can I identify which and how many parameters have been passedto the webmethod to insert/update the data to the DB.
I want to create a method with optional parameters in my wcf service. I am doing it like this
[Code]....
When I try to use it in my client application and try to pass the values only for first two parameters it gives me an error that"Argument not sepecified for parameter Status"
I have a controller method that is called with many different combinations of URL's. To overcome issue i am using optional parameters.here is my controller method signature...public ActionResult localMembersSearch(string Gender, string calling, [Optional]string Region, [Optional]string County, [Optional]string Town, [Optional]string queryvalues)the first two parameters are not optional but always expect
I want to add optional parameters in my routing table.For example I would like the users to browse a product catalog like this:http://www.domain.com/browse/by-category/electronics/1,2,3 etc
I've already implemented URL routing in my app but there are cases where I may or may not get a paramter. In particular, I'm trying to come up with a good way to handle multi-language support. For example, if my regular URL is /SomeCategory/Friendly-Topic-URL, I want to have an optional language selector at the end but I'd like to be optional. So, if I get /SomeCategory/Friendly-Topic-URL/es, that should bring up the topic in Spanish but if get nothing, that should bring up English.
I'm trying to implement a search function on an incident logging page that is working fine. Currently I am only able to search against one criteria at a time, using the following route:
I'm using the iis7 URL Rewrite module and it's working fine, except for two things. Being new to this, I might be missing something obvious.
1) My URL gets converted from www.mysite.com/search.aspx?fName=John&sName=Smith to www.mysite.com/John/Smith. This works fine, but if I add a trailing / , a few images on the site disappear, wheras a few don't. (They're all in the same location). However, the search results are fine.
2) Is it possible to make cerain querystrings optional? Server side, this is implemented (i.e. if nothing is entered, then assume a default value). But how would this work with the URL rewrite module? e.g. www.mysite.com/John would search for John and use a default value for the sName parameter.
I have a GridView bound to an DataSource query with parameters tied to form controls.What is the standard / best-practices way to handle optional query parameters?
I'm creating a webpage with serveral web controls to set search parameters for querying an SQL table. My plan is to use a TableAdapter to hold the query. If the user decides not to use one, several, or any of the web controls to filter their search, I want the SELECT to execute without complaining that it doesn't have parameter values. Should my SQL query look like
I have a data grid with a lot of information on it - to easily filter the data, I would like to be able to pass parameters to it. My problem is that I do not want the parameters to be required. So if I just put 1 or 2 of them in the query string, I would like for it to return all of the data related to those two parameters.I am using a data grid & stored procedures:My Stored Procedure looks like this:
How to return values from Webmethod to the client in JSON format? There are two static int values that i want to return.Do I need to create new object with those 2 properties and return it?The GetStatus() method is called frequently and i don't like the idea of creating a special object each time just for json formatting...
[WebMethod] public static int GetStatus() { int statusProcess,statusProcessTotal; Status.Lock.EnterReadLock(); statusProcess=Status.Process; //Static field statusProcessTotal=Status.ProcessTotal; //Static field Status.Lock.ExitReadLock(); return ... } On client side I catch the return value in : function OnSucceeded(result, userContext, methodName) (PageMethods.GetStatus(OnSucceeded, OnFailed);)
The problem is the double quotes wrapping everything under 'd'. Is there something I've missed in the web method or some other means of returning the data without the quotes? I don't really want to be stripping it out on the client everytime. Also I've seen other articles where this doesn't happen.
Upon clicking a button I need to send a collection and a few other variables to server in Json form.For each value in the collection the server code (C# ) wil update those other variables in the DB.
For example there is a ‘classnumber’ collection with values (First, Second, Third, ….),other variables (‘teacher_name’ and ‘subjectname’).For each value in the ‘classnumber’ collection I need to update the ‘teacher_name’ by searching for the ‘subject_name’ in the DB.So I need to pass the ‘classnumber’ collection,’teacher_name’,’subject_name’ values to server in json form. At the moment instead of sending the ‘classnumber’ collection I am sending ‘teacher_name’,’subject_name’,’classnumber’ as variables for each value in the collection ,which requires multiple requests made to the server.
Instead of these individual requests I am wondering if there is a way to send all the data at once to server in json form?
I have the following web method , no success on return a correct Json format.
[Code]....
GetAll() return list of type "Company" POCO classes.
The web method complaint type "Company" could not cast to object. However I could not just return the Company type because client side Json only accept its 2 properties -"CompanyName", "ID" and I want to keep it that way.
Of cause, I had tried create a CompanyDTO which only have those two properties, but same error - "Unable to cast object of type..."
How should I modify in my web method to make it able to return a list of partial "Company" type in Json format?