Controller get checkbox list from a view

0

I have a PartialView where I load a list of my object and put a checkbox for the user to mark which list item he wants to save, so I do not know how < in> controller can "know" which check is marked in view , remembering that I put a check property of my viewmodel .

    
asked by anonymous 06.02.2016 / 14:22

1 answer

0
  

..., remembering that I put a manual check , which is not a property of my viewmodel

This does not make much sense. In fact, you do not have the Controller to guess what you selected on the screen. You need to pass to the Controller a data model that supports CheckBoxes .

I already answered a very similar question some time ago , using a specific package to create CheckBoxes . You just have to point a good example of Binding , which I do below:

Model:

namespace MeuProjeto.ViewModels
{
    public class PostedFruitsViewModel
    {
        public string[] FruitIds { get; set; }
    }
}

Controller:

    [HttpPost]
    public ActionResult Index(PostedFruits postedFruits)
    {
        // Os Ids de Fruits selecionados estarão em postedFruits.FruitIds.
    }
    
27.08.2016 / 07:26