3
컨트롤러에 서비스 배열을 전달하려고합니다. 컨트롤러를 사용하기 전에 데이터를 직렬화하는 작업을 여러 가지 방법으로 시도했습니다. 각 서비스를 직렬화합니다. 컨트롤러 매개 변수를 문자열로 변경하고 배열을 serialize 한 다음 JsonConvert를 사용하여 작동하는 것으로 보입니다. 오히려하지 말라.Javascript 클래스의 배열을 MVC 컨트롤러에 전달 하시겠습니까?
지정된 코드를 사용하면 목록에 올바른 수의 항목이 나타납니다. 그러나 모두 빈 길드가있는 서비스 ID가 포함되어 있으며 서비스 공급자 ID는 null입니다.
아이디어가 있으십니까?
자바 스크립트
function ServiceItem() { this.ServiceProviderID = 'all'; this.ServiceID = ''; } var selecteditems= (function() { var services = new Array(); return { all: function() { return services; }, add: function(service) { services.push(service); } }; })(); var reserved = []; $.each(selecteditems.all(), function(index, item){ reserved.push({ ServiceID: item.ServiceID, ServiceProviderID: item.ServiceProviderID}); }); getData('Controller/GetMethod', { items: reserved }, function(result) { }); var getData = function (actionurl, da, done) { $.ajax({ type: "GET", url: actionurl, data: da, dataType: "json", async: true, success: function (d) { if (typeof (done) == 'function') { var str = JSON.stringify(d); done(JSON.parse(str)); } } }); };
컨트롤러
public JsonResult GetMethod(List<CustomObject> items) { }
public class CustomObject { public Guid ServiceID {get;set;} public Guid? ServiceProviderID {get;set;} }
그래 미안 해요, 난 나를 – jaekie
GetData의 실제로 내가 내 데이터베이스의 모든 호출에 사용하는 방법입니다 그것을 해결하자, 내 정확한 코드를 제공 didnt가 .. 그러나 나는 통과했다 {items : reserved} .. – jaekie
전통적 : 사실, 목록에 0 행이 포함되어 있지만 2 행 전에 비어 있습니다. – jaekie