How to pass list of checkboxes to ActionResult

3

I need to know how to pass the values of the inputs checkboxes to the action Edit , I need to pass the properties Checked and Id and store in a list of type Photo . Note that the controller that is running is not of the same type as the view , this control is of gallery , the model gallery has a property of type List<Photo> .

Below are the prints .

Model :

View:

Controller :

Printofthescreentounderstandthecontext:

    
asked by anonymous 20.03.2014 / 20:08

1 answer

4

Make your checkboxes look like this:

<input type="checkbox" name="photoToDeleteIds" value="@imagePath.IdPhoto" />

And change the action of your controller by adding a parameter photoToDeleteIds :

public ActionResult Edit(Gallery gallery, int[] photoToDeleteIds)
{
    // agora o parâmetro photoToDeleteIds contém os IDs das fotos que foram selecionadas
}

Or, change the class Gallery , including a PhotoToDeleteIds property:

class Gallery
{
    public int[] PhotoToDeleteIds { get; set; }
    // ... restante da classe
}

Note that there is a match between the input and the parameter or property names, depending on which path you choose. This match is not case sensitive.

    
20.03.2014 / 20:14