2017-04-15 4 views
0

Kann nicht scheinen, um die Antwort zu finden, ich bin für hier suchen ...jQuery Ajax-Aufruf Pass Parameter

NULL meiner ASP.net-Controller übergeben wird - iid hat einen Wert haben.

function Dismiss(iid) { 
    $.ajax({url: '@Url.Action("DismissNotification")', type: 'GET',Data: {id:iid}, success: function(result){ 
      $('#' + id).hidden(); 
    }}); 
} 

[Authorize] 
[HttpGet] 
public bool DismissNotification(string id) 
{ 
    if (!string.IsNullOrEmpty(id)) 
    { 
     _notificationService.Dismiss(id); 
     return true; 
    } 

    return false; 
} 

Irgendwelche Ideen?

Antwort

1

Die Einstellungen Eigenschaft, in denen der Client Daten an den Server sendet data genannt wird, nicht Data

Dies sollte funktionieren

$.ajax({ 
    url: '@Url.Action("DismissNotification")', 
    type: 'GET', 
    data: { id: iid }, 
    success: function (result) { 
     console.log('result',result); 
}}); 

Sie auch

$.get('@Url.Action("DismissNotification")', { id: iid }, function (result) { 
    console.log('r', result); 
}); 
als auch die $.get Methode verwenden können