0
votes

In my index page, i have multiple checkboxes that can be selected:

@foreach (var item in Model) {
    <tr>
        <td class ="text-nowrap">
            <input class="chkSelect" type="checkbox" name="Selected" value="@item.Id">
        </td> 
        <td>                
            @Html.ValueFor(modelItem => item.trandate, "{0:dd/MM/yyyy}")
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.Id })            
        </td>
    </tr>
}

I need to get the selected items and pass them to another form/page /action where i want to use the ids of the selected item to perform other actions. How do i pass the selected items to the controller action of the other page ?

so , now i created public ActionResult SendSMS(string[] msisdn) { return View(); } and

@using (Html.BeginForm("SendSMS", "Subscribers", FormMethod.Post))
{
    <div class="form-group">
        <a href="@Url.Action("SendSMS", "Subscriber", new { msisdn = Request["Selected"] })">   <span class="btn btn-primary"> <i class="fa fa-envelope"></i> Send SMS</span>  </a>
    </div>

}

So, will Request["Selected"] hold all the selected items? it appears null when debugging.

2
You need a form and post the values to an action method that has parameter int[] Selected - user3559349

2 Answers

0
votes

You could POST it to the controller and do a redirect with those values. The values would then do in a query strings to the other action. Like:

return RedirectToAction("Index", "Home", new { value1 = value1, value2 = value 2});
0
votes

I was able to get this done by simply using a submit button. and

and in the controller action SendSMS i have :

if (Request["Selected"] != null)
            {
                model.msisdn = string.Empty;
                model.MessageId = string.Empty;
                foreach (var selection in Request["Selected"].Split(','))
                {


                }
            }