2010-06-04 3 views
0

간단한 VS2010 .NET 4.0 MVC2 응용 프로그램에 문제가 있습니다.MVC2 JSON 입력

내 컨트롤러 액션은 다음과 같습니다

public JsonResult GetJson(string query)

내가 지금처럼 jQuery를 함께 작업에 액세스 :

function getJson() {
var postdata = {};
postdata['query'] = $('#query').val();
$.ajax({
type: "POST",
url: '<%= Url.Action("GetJson") %>',
data: JSON.stringify(postdata),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {

조치가 jQuery를 XHR 요청에 따라 실행,하지만됩니다 "쿼리"값이 항상 null인지 문제가됩니다. Firebug에서 POST 요청/응답을 볼 수 있으며 적절한 JSON 문자열이 액션에 전송 된 것을 보여줍니다.

무엇이 문제 일 수 있습니까? MVC가 JSON 입력을 파싱/역 직렬화하지 않는 것처럼 보입니다.

감사합니다. 당신을 위해 작동합니다으로

답변

0

이 시도하십시오

$.ajax({ 
    type: "POST", 
    url: '<%= Url.Action("GetJson") %>', 
    data: {query: $('#query').val()}, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function (msg) { 
    } 
});