简体   繁体   中英

Passing checkbox values between asp.net pages

On one ASP.NET page, I have a DataTable with a list of Investors. 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...

 $(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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