2013-08-19 565 views
0

我不能讓我的請求參數...請求查詢爲空

我做AJAX請求通過POST方法我的服務頁面,在我的瀏覽器控制檯,請求我好喜歡sended:

localhost/Services/?target=test&action=list&from=test 

發送這樣的:

$.ajax({ 
        url: '@Url.Action(Url.Content("../Services"))', 
        type: 'POST', 
        data: "target="+$(this).attr('id')+"&action=list&from=test", 
        dataType: 'string', 
        success: OnSuccess 
       }); 

在我的控制,我試過:

var context = System.Web.HttpContext.Current; 
var q = context.Request.QueryString; //empty 
var q2 = context.Request.Url.Query; //empty 
// or 
var id = Request.QueryString["target"].ToString(); //error - sample on the following link 

Get full query string in C# ASP.NET

怎麼回事?

+0

的網址是什麼? – glautrou

+0

你得到的錯誤是什麼 – Vignesh

+0

可能是這個幫助你 HttpContext.Current.Request.Form [「id」] – Mohit

回答

0

檢查您的global.ascx.cs文件的路線。看起來你沒有註冊路線。檢查此方法RouteConfig.RegisterRoutes(RouteTable.Routes);

0

我已經找到了,它就像:

var target = Request["target"]; 

如果能幫助別人^^