[RESOLVED] Using ActionLink with Listboxes.
Hi All,
I have the following code that initially populates 2 listboxes and I do the classic on screen of moving items between the 2 list boxes. This all works fine. To get the data from both listboxes back to my controller, I was using a combination of Jquery with an Ajax/JSON call and this was also working fine.
I have now been told that I cannot use the Ajax/Json combination and instead should use the ActionResult on the controller with an @Html.ActionLink.
The problem I have is that I cannot seem to get the items that are in the listboxes to postback on the action.
Here's the code:
Code:
<td style="width:46%">@Html.ListBox("Available", new MultiSelectList(Model.AvailableFloatingZones, "PolicyZoneID", "FullAddress"), new { style = "width:100%" })</td>
<td style="width:8%"><center><input type="button" name="add" id="add" value=">>" /><br /><br /><input type="button" name="remove" id="remove" value="<<" /></center></td>
<td style="width:46%">@Html.ListBox("Assigned", new MultiSelectList(Model.AllocatedFloatingZones, "PolicyZoneID", "FullAddress"), new { style = "width:100%" })</td>
these populate the listboxes. the 2 buttons use a bit of Javascript to move the items between the listboxes this is all ok.
as mentioned I originally had a submit button and then captured the values using:
Code:
var assignedArray = $.map($("#Assigned option"),
function (item) {
return $(item).attr("value");
});
the same for the other listbox before making an ajax call to the server passing these values. (all was working).
Now I need to change the submit button to something like :
Code:
@Html.ActionLink("Link/Unlink", "Link", "PolicyZone", new { policyZoneID = Model.PolicyZoneID, available = }, new { @class = "btnProcess" })
How do I get my Available list into the available variable? my method signature at the moment on the controller is:
Code:
public ActionResult Link(int policyZoneID, List<string> available )
{....
Re: Using ActionLink with Listboxes.
I was then told to use an @Html.ListBoxFor, but then to populate the model would have required ajax calls anyway back to the controller when shifting items between the 2 listboxes to populate the model, which with my original code didn't happen.
the powers that be have relented after finally agreeing that the way they were asking me to make this work was never going to happen. So, after spending 2 days chasing my tail they have relented and are letting me leave my code as was (working fine with Ajax).