I have the following controller signature:
public void DoSomething(string dialerJob, MyViewModel[] agentStates)
The presented models represent form fields in an array (selected elements in the HTML table). I figured out how to pass int form elements as an array argument to the controller thanks to Robert Koritnik.toDictionary () jQuery plug-in (http://erraticdev.blogspot.com/2010/12/sending-complex-json- objects to aspnet.html )
However, now I need to pass one additional parameter of the string (from the drop-down list) to the controller, and I cannot figure out how to do this. I tried various combinations, for example:
var job = $('#DialerJobs').attr('value'); var data1 = $.toDictionary(data, "agentStates"); $.ajax({ url: "/Blending/ChangeOutboundJob", type: "POST", dataType: "application/JSON", data: {job, data1} });
I also tried the following:
var job = $('#DialerJobs').attr('value'); var data1 = $.toDictionary(data, "agentStates"); $.ajax({ url: "/Blending/ChangeOutboundJob", type: "POST", dataType: "application/JSON", data: {dialerJob: job, agentStates: data1} });
But no one is working.
If I remove the dialerJob parameter from the data to send, the agents will be populated correctly in the controller. And what is sent looks like this:
agentStates[0].agentId=7654&agentStates[0].projectId=999&agentStates[0].stateId=1&agentStates
[0] .subStateId = 1 & agentStates [1] .agentId = 9876 & agentStates [1] .projectId = 999 & agentStates
[1] .stateId = 1 & agentStates [1] .subStateId = 1
But if I included dialerJob, then what is sent:
dialerJob=SomeJob&agentStates[0][name]=[0].agentId&agentStates[0][value]=84&agentStates[1][name]=
[0] .projectId & agentStates [1] [value] = 999 & agentStates [2] [name] = [0] .stateId & agentStates [2] [value]
= 1 & agentStates [3] [name] = [0] .subStateId & agentStates [3] [value] = 1 & agentStates [4] [name] = [1] .agentId & agentStates
[4] [value] = 15884 & agentStates [5] [name] = [1] .projectId & agentStates [5] [value] = 999 & agentStates [6] [name] = [1] .stateId & agentStates [6 ] [value] = 1 & agentStates [7] [name] = [1] .subStateId & agentStates [7] [value] = 1
That everything went bad ...