2015-11-03 68 views
0

我在工作中繼承了一些代碼,似乎無法獲取比第一個參數更多的代碼。如果我嘗試添加一個JSON對象,它似乎並沒有通過。前端用Ext.js編寫,後端用C#.NET 4.5編寫。如何接收從瀏覽器到.NET 4.5的請求C#

瀏覽器代碼:

 frame.onload = WorkManager.util.DownloadPrint.Unmask();   
     var form = Ext.get('iframeForm'); 
     if (form == null) { 
      form = body.createChild({ 
       tag: 'form', 
       cls: 'x-hidden', 
       id: 'iframeForm', 
       name: 'iframeForm', 
       standardSubmit: true, 
       method: 'POST', 
       //action: webroot + 'dispatch.aspx', 
       action: AppSettings.root + '/Download/GetExcelData/' + reqType, 
       params: {'startDate': 'test', 'endDate':'anothertest'}, 
       target: 'downloadIframe' 
      }); 

和後端代碼:

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Linq; 
using System.Net; 
using System.Web; 
using System.Web.Http; 
using System.Net.Http; 
using System.Net.Http.Headers; 
using System.Text; 
using Fcx.Fu.Tast.DBAccess.E2EUI; 
using Newtonsoft.Json.Linq; 

namespace Fcx.Fu.Tast.Xtra.WebApi.Controllers.E2Z 
{ 
//public class Dates { string startDate{get; set;} string endDate{get;   set;}} 
public class DownloadController : XtraBaseController 
{ 

    [AcceptVerbs("GET", "POST")] 
    public HttpResponseMessage GetExcelData(String id, JObject data) 
    { 


     switch (id) 
     { 
      case "xeDownload": 
       return GetExceptionData(id); 

      case "xaeDownload": 
       return GetAssetExceptionData(id); 

      case "oobDownload": 
       return GetOOBExceptionData(id); 

      case "techShortDownload": 
       return GetTechShortExceptionData(id); 

     } 
     return null; 
    } 

的 「ID」 成爲正確的,但在HttpResponseMessage JSON數據參數來在空...

+0

如果您使用Chrome瀏覽器,則可以查看網絡選項卡並查看請求標頭並查看它是否與您的API端點預期相符。 –

+0

嘗試使用類似提琴手或郵遞員的方式向端點發送POST請求。然後從那裏拿走 – Bowofola

回答

0

發送數據參數爲json。您當前正在發送未映射到方法參數的endDate。

params: {'startDate': 'test', data: { 'property1': 'value1', 'property2': 'value2', 'property3': { 'p3property1': 'p3value1' } },