我有一个自动完成文本框,我需要获取所有特定学位和学期的学生,因为这是收集degreeId并将其存储在全局声明的变量中并且正在收集学期,现在我需要通过自动完成文本框值,degreeId和semester ....为此我试着调用我的webservice,
$("#txtStudents").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
url: "/DataService.asmx/SearchStudents",
contentType: "application/json; charset=utf-8",
data: "{ 'searchTerm': '"+ JSON.stringify($("#txtStudents").val())+ "','degreeId': '"+JSON.stringify(degreeId)+"','semester': '"+JSON.stringify($("#ddlSemester :selected").text())+"'}",
dataType: "json",
success: function (data) {
我在webservice中收到此调用,
public string SearchStudents(string searchTerm, string degreeId, string semester)
{}
我有一个课程来获取特定学期和特定学位的学生详细信息,如
public class SearchStudents : List<SearchStudent>
{
DataAccess.Entities buDateEntities = new DataAccess.Entities();
public SearchStudents(string searchTerm)
{
//int sem = Convert.ToInt32(semester);
//int degree = Convert.ToInt32(degreeId);
foreach (DataAccess.Student student in buDateEntities.Students.Where(s => s.IsDeleted == false
// && s.DegreeId==degree
//&& s.CurrentSemester==semester
&& ((s.FirstName.IndexOf(searchTerm) == 0 || s.MiddleName.IndexOf(searchTerm) == 0 || s.LastName.IndexOf(searchTerm) == 0)
)|| s.USN.IndexOf(searchTerm) == 0).OrderBy(s => s.FirstName).Take(5))
{
this.Add(new SearchStudent(student.StudentId
, student.FirstName
, student.MiddleName
, student.LastName
, student.Photo
, student.USN
, student.Email
, student.Mobile));
}
}
}
如何从网络服务中调用(我需要传递searchTerm,degreeId,semester)这个类....
答案 0 :(得分:5)
...
data: {
searchTerm : $("#txtStudents").val(),
degreeId : degreeId,
semester : $("#ddlSemester :selected").text()
},
...
以这种方式定义它应该有效
答案 1 :(得分:1)
data: {
searchTerm : $("#txtStudents").val(),
degreeId : degreeId,
semester : $("#ddlSemester :selected").text()
},
将服务器函数参数转换为字符串,正如我所看到的那样,你正在传递字符串,并且在参数中你有int。
public string SearchStudents(string searchTerm, string degreeId, string semester)
注意:如果Json.Stringify
所有参数都更好。