asp.net mvc web api 参数输入多个参数
生活随笔
收集整理的這篇文章主要介紹了
asp.net mvc web api 参数输入多个参数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
部分代碼
apicontrol中
public class StudentController : ApiController { public HttpResponseMessage PostStudentsByReq(StudentReq studentReq, string criteria) { var students = studentRepository.GetAll().Where( s => string.Equals(s.age.ToString(), studentReq.age.ToString(), StringComparison.OrdinalIgnoreCase)); var response = Request.CreateResponse(HttpStatusCode.OK, students); return response; //return students; }}?
model 類
public class Student { public string name { get; set; } public int id { get; set; } public string gender { get; set; } public int age { get; set; } } public class StudentReq { public string name { get; set; } public int id { get; set; } public string gender { get; set; } public int age { get; set; } }?
前臺ajax jquery調(diào)用方法
function GetStudentByReq_Post() { alert("開始"); var studentReq = { name: 'ab', id: '1', gender: 'man', age: '15' }; var age = 22;? $.ajax({ url: 'api/student?criteria=full', type: 'POST', contentType: "application/json;charset=utf-8", data: JSON.stringify(studentReq), success: function (data) { alert("aa"); // WriteResponse(data); WriteResponses(data); }, error: function (x, y, z) { alert('The Student not found in the List for the given ID'); } }); //Displays in a Table function WriteResponses(students) { var strResult = "<table><th>Name</th><th>Student ID</th><th>Gender</th><th>Age</th>"; $.each(students, function (index, student) { strResult += "<tr><td>" + student.name + "</td><td> " + student.id + "</td><td>" + student.gender + "</td><td>" + student.age + "</td></tr>"; }); strResult += "</table>"; $("#divResult").html(strResult); } }?
html部分代碼
<div id="divResult" style="margin-left: 15px"></div><div> <button id="getStudentByReq2" onclick="GetStudentByReq_Post()">獲取列表</button></div>轉(zhuǎn)載于:https://www.cnblogs.com/z_lb/archive/2012/11/28/2792188.html
總結(jié)
以上是生活随笔為你收集整理的asp.net mvc web api 参数输入多个参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛腩新闻发布系统——初探CSS
- 下一篇: oracle for循环