user2536026
user2536026

Reputation: 3

How can i Pass values of checkBox those are checked to controller action in asp.net mvc 3 without using Ajax/JQuery in asp.net Mvc3

Upvotes: 0

Views: 9672

Answers (1)

Yellowfog
Yellowfog

Reputation: 2343

You have a bunch of checkboxes with the same name and different values. You could post them to a method that takes a FormCollection, ie.

    public ActionResult Test(FormCollection collection)
    {
        string results = collection["Blanks"];
    }

This would give you a comma-delimited list of values (or null, where no checkboxes are ticked).

Alternatively, if you have the possible values as an array on the server then you could give the checkboxes names according to their array values, which would mean you could do something like this:

@using (Html.BeginForm("Test","Home"))
{
    @Html.CheckBox("Blanks[0]", false);
    @Html.CheckBox("Blanks[1]", false);
    @Html.CheckBox("Blanks[2]", false);

    <input type="submit" value="Submit" />
}

giving you an array of booleans in your Test method:

public ActionResult Test(bool[] Blanks)
{        }

Upvotes: 1

Related Questions