1

I have multiple checkboxes with the same name. Like this:

    <input name="zones" value="@zoneItem.Id" type="checkbox" /><label>@zoneItem.Name</label></span>
<input name="zones" value="@zoneItem.Id" type="checkbox" /><label>@zoneItem.Name</label></span>
<input name="zones" value="@zoneItem.Id" type="checkbox" /><label>@zoneItem.Name</label></span>

but in get or post i can't get which ones are checked. How can i do it?

2 Answers 2

3

They should have different values. Right now you gave them all the same value. So once you give them different values:

<input name="zones" value="1" type="checkbox" />
<input name="zones" value="2" type="checkbox" />
<input name="zones" value="3" type="checkbox" />

in your controller action you will get the list of values of those that were checked:

public ActionResult Foo(string[] zones)
{
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

0

They can be retrieved by adding a parameter to your action method.

public ActionResult GetData(Guid[] zones)
{
}

Make sure the array type matches your Id type.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.