jQuery ajax加载问题与MVC控制器的参数

介绍

我正在使用带有WebApi 2.0和jQuery的ASP.NET MVC 5。

问题

我正在尝试显示一个模式,其中包含来自ajax调用的用户详细信息。 使用$.getJSON()我成功地收到了来自WebApi的Json格式的用户详细信息。 现在我想使用局部视图在我的模态中加载html。

我尝试使用以下代码,但html没有加载。 在我的控制台中,我看到了带有正确数据和html的请求和响应。

 loadItem: function () { var $a = $(this); var id = $a.attr('data-id'); $.getJSON(uri_api + '/' + id) .done(function (data) { console.log(JSON.stringify(data)); $.ajaxSetup({ contentType: 'application/json; charset=utf-8', dataType: 'json', cache: false }); // Get the partial view to show in modal $.ajax({ type: 'POST', data: JSON.stringify(data), url: uri_internal + '/getuserdetails', done: function (result) { var $modal = $('#modalUserDetails'); $modal.html(result); $modal.modal('show'); }, fail: function (jqXHR, textStatus, err) { console.log('Error: ' + err); } }); }) .fail(function (jqXHR, textStatus, err) { console.log('Error: ' + err); }); } 

然后我使用另一个ajax函数.load()直接加载html但现在我没有收到任何东西。 在我的控制器中放置断点也不会触发,我收到500内部服务器错误。

我用于加载的代码:

 $.getJSON(uri_api + '/' + id) .done(function (data) { console.log(JSON.stringify(data)); $.ajaxSetup({ contentType: 'application/json; charset=utf-8', dataType: 'json', cache: false }); // Get the partial view to show in modal var $modal = $('#modalUserDetails'); $modal.load( uri_internal + '/getuserdetails', { user: JSON.stringify(data) }, function () { } ); $modal.modal('show'); }) .fail(function (jqXHR, textStatus, err) { console.log('Error: ' + err); }); 

我的控制器在哪里:

 public ActionResult GetUserDetails(User user) { return PartialView(user); } 

以及用于加载数据的模态html:

  

部分观点:

 @model ProsecMdmHelper.Models.User  

500错误:

 "Invalid JSON primitive" in Ajax processing: user