我正在使用剃刀,并且很难将数组传递给控制器。数组包含我制作的对象,而我正在尝试这样做:
$.ajax({ type: "POST", url: "HomePage/HandleOperations", data: JSON.stringify(operationCollection), success: function (data) { alert("SUCESS");}, dataType: "json", contentType: "application/json" });
而我的控制器是:
public void HandleOperations(List<string> operationCollection) { }
我不需要使用ajax,但是我不确定该怎么做。在控制器中,它表明“ operationCollection”包含元素,但它们都为空。
客户端:
$.ajax({ type: "POST", url: "HomePage/HandleOperations", data: {operations: operationCollection}, success: function (data) { alert("SUCCESS"); } });
并声明一个类服务器端,如下所示:
public class Operation { public int Index; public string Source; public string Target; public int AddOrDel; }
那么您可以执行以下操作:
public void HandleOperations(Operation[] operations) { }