如何在asp.net mvc中将所选项目从一个页面传递到另一个页面

时间:2023-01-18 10:04:27

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 ?

我需要获取所选项目并将它们传递给另一个表单/页面/操作,我想使用所选项目的ID来执行其他操作。如何将所选项目传递给另一页面的控制器操作?

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

所以,现在我创建了公共ActionResult SendSMS(string [] msisdn){return View();和

@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.

那么,Request [“Selected”]会保留所有选定的项目吗?它在调试时显示为null。

2 个解决方案

#1


0  

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});

#2


0  

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

我只需使用提交按钮即可完成此操作。和

and in the controller action SendSMS i have :

并在控制器动作SendSMS我有:

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


                }
            }

#1


0  

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});

#2


0  

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

我只需使用提交按钮即可完成此操作。和

and in the controller action SendSMS i have :

并在控制器动作SendSMS我有:

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


                }
            }