mardi 21 juillet 2015

MVC 5 remove ViewModel's list element with checkbox

I have a ViewModel with a list how can I remove the list elements using checkboxes? I generate checkboxes with a foreach in the edit action, but how can I get the checkboxes' value beside the ViewModel with HttpPost?

<dl>
     @foreach (var flower in Model.FlowerList)
     {
         <dt><input type="checkbox" id="@flower.Id"/></dt>
         <dd>@flower.Name</dd>
     }
</dl>

With this code down I can get only the viewmodel's values, but not the checkboxes' because they are not part of the viewmodel.

[HttpPost]
[ValidateAntiForgeryToken]
public override ActionResult Edit(int id, BouquetViewModel viewModel)
{
    if (!ModelState.IsValid)
    {
        return View(viewModel);
    }
    DataService.Update(viewModel);
    return RedirectToAction("Details/" + id);
}




Aucun commentaire:

Enregistrer un commentaire