Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Code for delete will be written in the HttpPost action for delete. Something like below should work if you are using <code>myModel</code></p> <pre><code>[HttpPost] public ActionResult Delete(myModel deleteEntries) //This is the post-version of your Action that rendered the view..If it's Edit, then change the name to Edit { var deleteList = db.deleteEntries.where(d =&gt; d.checkBox == true).ToList(); foreach (myList my in deleteList) { db.myList.Remove(my); // remember db should be your DbContext instace } db.SaveChanges(); } </code></pre> <p><strong>UPDATE</strong></p> <p>You will first need to make a ViewModel because otherwise you cannot recognize which entries are checked for deletion with the help of checkbox.</p> <p>Make a ViewMode class like following</p> <pre><code>using pratice3.Models; public class MyPhotoViewModel { public UserManagementDbEntities.tblPhoto TablePhoto { get; set; } public bool checkBox { get; set; } } </code></pre> <p>Return this to your view</p> <pre><code>[AcceptVerbs(HttpVerbs.Get)] public ActionResult PhotosList() { var viewModel = _datamodel.tblPhoto.Select(g =&gt; new MyPhotoViewModel { TablePhoto = g; checkBox = false; }).ToList(); return View(viewModel); } </code></pre> <p>In View, change the using statement to reflect <code>IEnumerable&lt;MyPhotoViewModel&gt;</code> and make appropriate changes accordingly. </p> <p>Then, define your Post Action like following</p> <pre><code>[HttpPost] public ActionResult PhotosList(IEnumerable&lt;MyPhotoViewModel&gt; myPhotoList) { var deleteList = myPhotoList.where(d =&gt; d.checkBox == true).ToList(); foreach (var deletePhoto in deleteList) { _datamodel.tblPhoto.DeleteObject(deletePhoto.TablePhoto); } db.SaveChanges(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload