我有WebMethod
:
[WebMethod]
public static string[] getDropDown(int idSpacies)
{
var raceList = from r in db1.breed where r.spaciesID == idSpacies select r;
string[] temp = new string[raceList.Count()];
int counter = 0;
foreach (var item in raceList )
{
temp[counter] = item.name;
counter++;
}
return temp;
}
和JavaScript功能:
function changeSpacies()
{
var temp = document.getElementById("selectpicker").value;
var availableTags = @Html.Raw(Json.Encode(AlewetWeb.Areas.ClinicService.Controllers.BreedsController.getDropDown(temp)));
$("#tags").autocomplete({
source: availableTags
});
}
当我在temp
WebMethod
来电中使用getDropDown
变量作为参数时,我收到错误
temp不存在于当前上下文中
如何将JavaScript变量传递给WebMethod
。