简体   繁体   English

在ASP.NET页面之间传递复选框值

[英]Passing checkbox values between asp.net pages

On one ASP.NET page, I have a DataTable with a list of Investors. 在一个ASP.NET页上,我有一个带有投资者列表的DataTable The client wanted a feature added that would allow their users to select individual investors from that list and and have an email button that would open up an email page and populate the bcc with the investor emails. 客户希望添加一项功能,该功能允许其用户从该列表中选择单个投资者,并具有一个电子邮件按钮,该按钮将打开一个电子邮件页面,并用投资者电子邮件填充密件抄送。 So far, I have gotten the checkboxes implemented, and I am successfully going through the checkboxes and grabbing the emails of only the checked boxes. 到目前为止,我已经实现了复选框,并且我已经成功地浏览了复选框并仅抓取了复选框的电子邮件。 From this point, I am completely lost as to how to send that date over to the next page and have them fill into the bcc automatically. 从这一点上,我完全不知道如何将日期发送到下一页并将它们自动填充到密件抄送中。 Here is my code so far: 到目前为止,这是我的代码:

<a onclick="grabEmail()" href="/Settings/EmailSelect" class="button blue" >Email Selected</a> 
...
...
...
<script type="text/javascript">
    function grabEmail() {
    var emails = new Array();
    var $checked = $('[@id=investoremails:checked');
    $checked.each(function () {
        emails.push($(this).val());
        alert($(this).val()); //This was just to check to make sure emails 
                              //were grabbed
    }

    );

    $.ajax({
        url: '/Settings/EmailSelect/',
        type: "POST",
        data: emails,
        traditional: true,

    });
}   

Then, on EmailSelect page... 然后,在EmailSelect页面上...

 $(document).ready(function() {
    $.ajax({
        type: "GET",
        url: "/Settings/EmailSelect",
        error: function (xhr, status, error) {
            $("#results").html("An error occurred: " + error).addClass("notification error");
            return false;
        },
        success: function(response) {
            if (response != null) {
                if (!response.Successful) {
                    $("#results").html("An error occurred: " + response.Exception).addClass("notification error");
                    return false;
                } else {
                    $("#bcc").val(response.ReturnVal);
                }
            }
        }
    });
});

And for the Controller.. 对于控制器

public ActionResult EmailSelect(string[] emails)
    {
        ViewData["Selected"] = emails;
        return View();
    }

We have somewhat similar functionality in this program where Investors can be part of user created groups, and there's another email page where the user can select a specific group to email to, and I was trying to base the solution for this problem off that (even though they are inherently different..). 在此程序中,我们有一些类似的功能,其中投资者可以成为用户创建的组的一部分,还有另一个电子邮件页面,用户可以在其中选择要发送给特定组的电子邮件,而我试图以此为基础解决此问题(甚至尽管它们本质上是不同的..)。 If anyone can point me in the right direction, that would be great! 如果有人能指出我正确的方向,那就太好了!

I should have answered this awhile ago, but I forgot to post it. 我应该早就回答这个问题,但是我忘了张贴它。

I did some research on MVC forms and how they interact with the controller, and I was easily able to get this to work by pulling the checkboxes in as a string array into the controller, and then passing them to the next page in ViewData. 我对MVC表单及其与控制器的交互方式进行了一些研究,通过将复选框作为字符串数组拉入到控制器中,然后将其传递到ViewData的下一页,可以轻松地使它起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM