I want to pass 2 arguments to my controller. Identifier and Object [].
Here is my controller:
[HttpPost] public string SaveCoordinates(string Id, object[] pFrame) { string rslt = "ERROR"; if (pFrame != null) { try { List<Coordinates> pList = new List<Coordinates>(); for (int i = 0; i < pFrame.Length; i++) { Dictionary<string, object> kvps = (Dictionary<string, object>)pFrame[i]; pList.Add(new Coordinates { Position = Convert.ToInt32(kvps["position"]), Height = Convert.ToInt32(kvps["height"]), Width = Convert.ToInt32(kvps["width"]), Top = Convert.ToInt32(kvps["top"]), Left = Convert.ToInt32(kvps["left"]) }); } MongoDBSaveOneFrameCoordinates(Id, pList); rslt = "SUCCESS"; } catch (Exception ex) { }
I know that the way I wrote the method may be wrong, but I'm just confused about how I can pass both the string id and the object in an ajax call. Here is my ajax call:
$.ajax({ url: '/Member/SaveCoordinates/@Model.Id', type: "POST", data: window.image.pinpoints, success: function (data) { alert(data); }, error: function () { alert("error"); } }); return false; }); });
@ Model.Id should be the identifier that I want to pass to the "Id" parameter of my controller, and window.image.pinpoints is the object I want to go through the "pFrame" object. How can I do this, so that both parameters are passed correctly? I think this may be due to the way I write the ajax jquery function.
source share