Asp.net mvc 4 在MVCWebAPI中使用Jquery数据库,得到404错误?
当我试图从Jquery Datatables调用我的web api时,我得到了一个404 Not Found异常: 我的请求URL:Asp.net mvc 4 在MVCWebAPI中使用Jquery数据库,得到404错误?,asp.net-mvc-4,jquery-datatables,asp.net-web-api,Asp.net Mvc 4,Jquery Datatables,Asp.net Web Api,当我试图从Jquery Datatables调用我的web api时,我得到了一个404 Not Found异常: 我的请求URL: http://someurl/API/LeaveRequest?sEcho=1&iColumns=13&sColumns=FirstName%2CFirstName%2CLastName%2CContactTypeDesc%2CTitle%2CPhone%2CEmail%2CFirstName%2CFirstName%2CLastName%2CCo
http://someurl/API/LeaveRequest?sEcho=1&iColumns=13&sColumns=FirstName%2CFirstName%2CLastName%2CContactTypeDesc%2CTitle%2CPhone%2CEmail%2CFirstName%2CFirstName%2CLastName%2CContactTypeDesc%2CTitle%2CEmail&iDisplayStart=0&iDisplayLength=10&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&mDataProp_5=5&mDataProp_6=6&mDataProp_7=7&mDataProp_8=8&mDataProp_9=9&mDataProp_10=10&mDataProp_11=11&mDataProp_12=12&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true&bSortable_6=true&bSortable_7=true&bSortable_8=true&bSortable_9=true&bSortable_10=true&bSortable_11=true&bSortable_12=true&userId=0
当我将url放入浏览器时,我得到“没有找到与请求URI匹配的HTTP资源”
我用一个参数尝试了一个简单的Get调用:
http://someurl/API/LeaveRequest/1
我对此没有异议。但不确定如何格式化数据表中的多个参数
我的客户代码如下:
function DisplayLeaveRequests() {
var oTable = $('#leaveList').dataTable({
"bServerSide": true,
"sAjaxSource": "/API/LeaveRequest",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback,
"error": handleAjaxException // this sets up jQuery to give me errors
});
},
"oLanguage": { "sZeroRecords": "No requests available", "sEmptyTable": "No requests available" },
"fnServerParams": function (aoData) {
aoData.push({ "name": "userId", "value": 0 }
);
},
"bProcessing": true,
"bDeferRender": true,
"iDisplayLength": 10,
"bLengthChange": false,
"bDestroy": true,
"bFilter": false,
"aoColumns": [
{ "sName": "FirstName" },
{ "sName": "FirstName" },
{ "sName": "LastName" },
{ "sName": "ContactTypeDesc" },
{ "sName": "Title" },
{ "sName": "Phone" },
{ "sName": "Email" },
{ "sName": "FirstName" },
{ "sName": "FirstName" },
{ "sName": "LastName" },
{ "sName": "ContactTypeDesc" },
{ "sName": "Title" },
{ "sName": "Email" }
],
"sPaginationType": "full_numbers"
});
}
我的web api(LeaveRequestController.cs)代码:
公共类LeaveRequestController:ApicController
{
//获取api/
公共字符串Get(int?iDisplayStart,
int iDisplayLength,
字符串搜索,
字符串过滤器列,
字符串过滤器选择,
布尔贝斯卡佩雷格克斯,
int iColumns,
int iSortingCols,
int iSortCol_0,
字符串0,
int sEcho,
int用户ID)
{
RequestRepository=新建RequestRepository();
IEnumerable requests=rep.Get().ToList();
var json=来自请求中的
选择ConvertProperty.Convert(新建
{
a、 叶状体,
a、 名字,
a、 姓,
a、 爆炸品,
等
我需要为所有参数创建对象,例如:
参数对象:
public class jQueryDataTableParamModel
{
/// <summary>
/// Request sequence number sent by DataTable,
/// same value must be returned in response
/// </summary>
public string sEcho { get; set; }
/// <summary>
/// Text used for filtering
/// </summary>
public string sSearch { get; set; }
/// <summary>
/// Number of records that should be shown in table
/// </summary>
public int iDisplayLength { get; set; }
公共类jQueryDataTableParamModel
{
///
///数据表发送的请求序列号,
///响应中必须返回相同的值
///
公共字符串sEcho{get;set;}
///
///用于过滤的文本
///
公共字符串搜索{get;set;}
///
///表中应显示的记录数
///
公共int iDisplayLength{get;set;}
在Get方法中使用param对象:
// GET api/<controller>
public string Get(jQueryDataTableParamModel param)
{
//获取api/
公共字符串Get(jQueryDataTableParamModel参数)
{
// GET api/<controller>
public string Get(jQueryDataTableParamModel param)
{