请求发布的表单数据的ASP.net始终为null

时间:2016-02-01 17:38:02

标签: c# asp.net forms null

以下Javascipt:

$.ajax({
    type: "POST",
    data: "langID=" + viewingLangID + "&currency=" + newVal + "&basePrices=" + pricePostData,
    dataType: "json",
    url: "/handlers/payments/getconversions.ashx",
    success: function(data) {

生成以下HTTP请求:

General
Request URL:https://127.0.0.1:3333/handlers/payments/getconversions.ashx
Request Method:POST
Status Code:200 OK
Remote Address:127.0.0.1:3333

Response Headers
Cache-Control:private
Content-Length:78
Content-Type:application/json; charset=utf-8
Date:Mon, 01 Feb 2016 17:35:41 GMT
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-MiniProfiler-Ids:["9d45ff72-2efa-4d31-a5c7-c109573699c6"]
X-Powered-By:ASP.NET

Request Headers
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Category:application/x-www-form-urlencoded; charset=UTF-8
Content-Length:62
Content-Type:text/plain;charset=UTF-8
Cookie:C3_Login=ID=e99af6ee-b0fc-4d92-89f6-262d37d7a2b0&Key=BAFKzQhxZsknMyE1bvbjsFouDvaZUSxVzP0oGmN8kONCJRUR1z; _gat=1; _ga=GA1.1.1302222369.1453808296; C3_Currency=GBP
Host:127.0.0.1:3333
Origin:https://127.0.0.1:3333
Referer:https://127.0.0.1:3333/?p=ContentIndividuals
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36
X-Requested-With:XMLHttpRequest

Request Payload
langID=2&currency=GBP&basePrices=299,799,2499,9999,10999,13999

但是,getconversions.ashx如果我这样做:

context.Request.Form["currency"]

值始终为null。知道为什么会这样吗?我已尝试过请求[“货币”]和Request.Params["currency"],但它始终返回null

如果我记录context.Request.ServerVariables [“ALL_RAW”]

Connection: keep-alive
Content-Length: 62
Content-Type: text/plain;charset=UTF-8
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: C3_Login=ID=e99af6ee-b0fc-4d92-89f6-262d37d7a2b0&Key=BAFKzQhxZsknMyE1bvbjsFouDvaZUSxVzP0oGmN8kONCJRUR1z; _gat=1; _ga=GA1.1.1302222369.1453808296; C3_Currency=GBP
Host: 127.0.0.1:3333
Referer: https://127.0.0.1:3333/?p=ContentIndividuals
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36
Content-Category: application/x-www-form-urlencoded; charset=UTF-8
Origin: https://127.0.0.1:3333
X-Requested-With: XMLHttpRequest

1 个答案:

答案 0 :(得分:0)

尝试将数据转换为对象。目前,数据不是json格式。

var jsonData = {'langID':viewingLangID, 'currency':newVal, 'basePrices':pricePostData}

$.ajax({
    type: "POST",
    data: jsonData,
    dataType: "json",
    url: "/handlers/payments/getconversions.ashx",
    success: function(data) {

另请注意,pricePostData的值应为json [123,234,456,567]等的数组。

希望这有帮助