0

I'm using ASP.NET MVC 4 with EF.

I want to add CheckBox at the end of every row.(this checkbox is not in my Model)

grid.Column("Verified", format: @<text><input name="cbVerify" type="checkbox" value="@??"/></text>)
...
@Html.ActionLink("Verified", "Verified", "Items")

And the selected rows I want to update all the selected records

    [HttpPost]
    public ActionResult Edit(items items)
    {
        if (ModelState.IsValid)
        {
            db.items.Attach(items);
            items.status = 4 ; //verified
            items.date_verif = Datetime.Now;
            db.ObjectStateManager.ChangeObjectState(items, EntityState.Modified);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(items);
    }
    public ActionResult Verified()
    {
        //var req = Request[""];??
        foreach(// selected rows)
        {
           //Edit(items); ?
        }
        return RedirectToAction("Index");
    }

Q: How can I update several selected rows from a button ?

tereško
  • 58,060
  • 25
  • 98
  • 150
Misi
  • 748
  • 5
  • 21
  • 46

1 Answers1

0

What you could do is simply have the value be the ID of the item you are looking to update (or if you do not even have that, a counter from 1 to number of rows), something like this in the view:


@using (Html.BeginForm()) {
    <input type="checkbox" name="verify" value="1" />
    <input type="checkbox" name="verify" value="2" />

    <input type="submit" value="Submit" />
}

Then in the controller post action, just take an array of (in my case) ints and act on whether the ID or row number in question is posted in the array.

So the action method looks like this for me (but you would obviously have other parameters before such as your view model):


[HttpPost]
public ActionResult Index(int[] verify)
{
    return View();
}
Mirko
  • 4,284
  • 1
  • 22
  • 19