I have the following function on WebService with 3 optional params:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string ObtenirPoble(string CP = "", int Codi = 0, string Nom = "")
{
List<clsPoble> llista = _r.getListPobles(CP, Codi, Nom);
JavaScriptSerializer jss = new JavaScriptSerializer();
string resultat_Json = jss.Serialize(llista);
return resultat_Json;
}
The problem is not to make optional params because i already make it on the WebService.
My problem is when i'm sending an ajax call using json with just 1 param like this because it trigger the error before run WebService code
//Object to send
var dataObject = {};
dataObject[config.busqueda] = $(elemId).val();
var json = JSON.stringify(dataObject);
$(elemId).autocomplete({
source: function (request, response) {
$.ajax({
url: config.webService,
data: json,
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
//Code...
}
});
}
});
And i get the following error "Invalid call to the Web service. Missing value for the parameter".
I know that i can solve this sending default values of all params but my question is if is possible to send just one param and how i can do this?