Controller get checkbox list from a view

Asked

Viewed 139 times

0

I have a Partialview where I upload a list of my object and put a checkbox so the user can mark which list item he wants to save, so I don’t know how the controller can "know" which check in is marked in the view, remembering that I put a check in manual, which is not a property of my viewmodel.

  • Give more dates so we can help you.

1 answer

0


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

This doesn’t make much sense. In fact, there’s no way Controller guess what you selected on screen. You need to pass to the Controller a data model that admits Checkboxes.

I already answered a very similar question some time ago, using a specific package to create Checkboxes. It was only necessary to point out 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.
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.