2017-02-13 3 views
1

のパラメータに渡すことはできません。jquery ajaxでテスト時の値を渡しているときに、コードの背後に値が表示されないという問題に直面しています。jquery ajaxからのコードをC#

function CreateComplaint(){ 

var category  = $('#ddlCompCategory') .val(); 
var name   = $('#txtCompUserName') .val(); 
var subject  = $('#txtCompSub')  .val(); 
var mobile   = $('#txtCompMobileNo') .val(); 
var address  = $('#txtaCompAddr') .val(); 
var email   = $('#txtCompEmail') .val(); 


$('#spinnerAddComplaint').show(); 
CreateComplaintXHR(
        '/api/Complaints/CreateComplaint', 
        { 
         Token  : RBApp.Token, 
         CategoryId : category, 
         UName  : name, 
         Subject  : subject, 
         Mobile  : mobile, 
         Email  : email, 
         Address  : address 
        }, ....} 

AJAX機能:

function CreateComplaintXHR(url, data, success, error, alWaysCallback) { 
    $.ajax({ 
     url: url, 
     type: 'POST', 
     dataType: 'json', 
     data: data, 
     success: function (data, textStatus, jqXHR) { 

      if (success) 
       success(data, textStatus, jqXHR); 
     }, 
     error: function (jqXHR, textStatus, errorThrown) { 

      if (error) 
       error(jqXHR, textStatus, errorThrown); 
     } 
    }).always(function() { 

    }); 

    } 

コードの背後にある:

[HttpPost] 
    [ActionName ("CreateComplaint")] 
    public ResponseModel InsertComplaintMethod(InsertComplaint Complaint) 
    { 
     log .Debug ("Create Complaint request received : "); 
     log .Debug ("Request params : " + Complaint .Serialize()); 

     User user = loadUser (Complaint .Token); 

     ComplaintsAdapter adapter = new ComplaintsAdapter (user); 

     ResponseModel response = adapter .CreateComplaintOrSuggestion (Complaint); 



     return response; 
    } 

InsertComplaintは

public class InsertComplaint 
{ 
    //public string Token { get; set; } 
    public string Lat = "0"; //{ get; set; } 
    public string Lng = "0"; //{ get; set; } 

    public string deviceID = "0"; 
    public string complaintSubject { get; set; } 
    public string complaintText { get; set; } 

    public string name { get; set; } 
    public string phoneNumber { get; set; } 
    public string attachements = null; 


    } 

insertComplaintMethodでは関数オブジェクトの苦情は、そのshowin代わりに任意の値を取得されていませんgヌル。これは問題です。なぜなら、ajax関数のデータは、より多くのプロパティを持つcomplaintオブジェクトよりもパラメータが少ないからです。誰でも手伝うことができます。ありがとうございます。

答えて

1

ここに名前

{ 
         Token  : 'test', 
         CategoryId : 'test', 
         UName  : 'test', 
         Subject  : 'test', 
         Mobile  : 'test', 
         Email  : 'test', 
         Address  : 'test' 
} 

、ここ

public class InsertComplaint 
{ 
    //public string Token { get; set; } 
    public string Lat = "0"; //{ get; set; } 
    public string Lng = "0"; //{ get; set; } 
    public string deviceID = "0"; 
    public string complaintSubject { get; set; } 
    public string complaintText { get; set; } 
    public string name { get; set; } 
    public string phoneNumber { get; set; } 
    public string attachements = null; 
} 

同じである必要があります。例えば、この1

phoneNumber : '123' 

で、このライン

Mobile : 'test', 

を交換し、あなたがnullではない、 '123' を表示されます。

+0

ありがとうございます。私は問題を理解するために2日を費やしました。できます。再度、感謝します。 –

+0

あなたは大歓迎です! – Pavlo

関連する問題