Is is possible to return two values from a WebService to jQuery.
I tried like
[WebMethod(EnableSession = true)]
public string testing(string testId)
{
string data = string.Empty;
string data1 = string.Empty;
List<test1> datalist1 = new List<test1>();
List<test> datalist = new List<test>();
//coding
data = jsonSerialize.Serialize(datalist1);
data1 = jsonSerialize.Serialize(datalist);
return [data,data1];
}
but its showing error....how can we return two values from webservice here.....
No, you can not have two returns in a function, the first return will exit the function you will need to create an object.
You can return multiple values by bundling those values into a dictionary, tuple, or a list. These data types let you store multiple similar values. You can extract individual values from them in your main program. Or, you can pass multiple values and separate them with commas.
Create a function getPerson(). As you already know a function can return a single variable, but it can also return multiple variables.
No you cannot return more than one value. But you can send an array of strings containing all those strings. Save this answer.
Another way is to create a custom data type that has the two return values you want:
[Serializable]
public sealed class MyData
{
public string Data { get; set; }
public string Data1 { get; set; }
}
...
[WebMethod(EnableSession = true)]
public MyData testing(string testId)
{
string data = string.Empty;
string data1 = string.Empty;
List<test1> datalist1 = new List<test1>();
List<test> datalist = new List<test>();
//coding
data = jsonSerialize.Serialize(datalist1);
data1 = jsonSerialize.Serialize(datalist);
return new MyData { Data = data, Data1 = data1 };
}
OR
[Serializable]
public sealed class MyData
{
public List<test> Data { get; set; }
public List<test1> Data1 { get; set; }
}
...
[WebMethod(EnableSession = true)]
public string testing(string testId)
{
MyData data = new MyData();
string alldata = string.Empty;
List<test1> datalist1 = new List<test1>();
List<test> datalist = new List<test>();
//coding
data.Data = datalist1;
data.Data1 = datalist;
alldata = jsonSerialize.Serialize(data);
return alldata;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With