Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7040707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:57:01+00:00 2026-05-28T01:57:01+00:00

I have list page to show all images with its name from database in

  • 0

I have list page to show all images with its name from database in asp.net mvc list action (PhotoList – get).. in that view page (PhotoList.aspx), I have created checkbox to delete multiple rows. I want scenario like following

First page shows the list with in first column checkbox and in second column PhotoName and on the down page one button for delete selected rows .
when selects checkboxes and clicks the delete button, according to selection the rows will be deleted from database and return the same list page..

I don’t understand where to write code for delete and how?

<% foreach (var item in Model) { %>
    <tr>
        <td>
             <input type="checkbox" name="deleteImage" value="<%= item.PhotoId %>"/>
        </td>
        <td>
            <%= Html.ActionLink("Edit", "Edit", new { id=item.PhotoId }) %> 
        </td>
        <td>
            <%= Html.Encode(item.PhotoName) %>
        </td>
    </tr>
<% } %>
<input type="button" name="Delete" value="Delete Selected items"/>      
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:57:01+00:00Added an answer on May 28, 2026 at 1:57 am

    The Code for delete will be written in the HttpPost action for delete. Something like below should work if you are using myModel

    [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 => d.checkBox == true).ToList();
        foreach (myList my in deleteList)
        {
            db.myList.Remove(my); // remember db should be your DbContext instace
        }
        db.SaveChanges();
    }
    

    UPDATE

    You will first need to make a ViewModel because otherwise you cannot recognize which entries are checked for deletion with the help of checkbox.

    Make a ViewMode class like following

    using pratice3.Models; 
    public class MyPhotoViewModel
    {
        public UserManagementDbEntities.tblPhoto TablePhoto { get; set; }
        public bool checkBox { get; set; }
    }
    

    Return this to your view

    [AcceptVerbs(HttpVerbs.Get)] 
    public ActionResult PhotosList() 
    {
        var viewModel = _datamodel.tblPhoto.Select(g => new MyPhotoViewModel
                                       {
                                           TablePhoto = g;
                                           checkBox = false;
                                       }).ToList();      
        return View(viewModel); 
    }
    

    In View, change the using statement to reflect IEnumerable<MyPhotoViewModel> and make appropriate changes accordingly.

    Then, define your Post Action like following

    [HttpPost]
    public ActionResult PhotosList(IEnumerable<MyPhotoViewModel> myPhotoList) 
    {
        var deleteList = myPhotoList.where(d => d.checkBox == true).ToList();
        foreach (var deletePhoto in deleteList)
        {
            _datamodel.tblPhoto.DeleteObject(deletePhoto.TablePhoto); 
        }
        db.SaveChanges();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a foreach that displays all the thumbnail images from a list of
I have a page with a list of items initially loaded from a include_once('show_calendarV2.php');
I have a list of images which I want to display in a page.
I have a list of images with various sizes and I have to show
I have a list if divs which contain images. I need to randomly show
I have list of articles on the page in table and i want to
I have a website that has products list page and product detail page .
I am using MVC3 and Entity Framework. I have a List on a page
I have a list view on a page and am trying emulate the toggling
I have a list of items on my web page that the user can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.