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 7505059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:46:59+00:00 2026-05-29T21:46:59+00:00

I have a view which lists students. I want to add a delete icon(

  • 0

I have a view which lists students. I want to add a delete icon( a red “x”) in front of each student. clicking on the delete icon will delete that student.

I know how to do it by entering a student id in a text box and adding a button to doing this. But I want to do the same by clicking a delete icon in front of each student.

Here is my view code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="Student.Models" %>

<asp:Content ID="Content3" ContentPlaceHolderID="TitleContent" runat="server">
    Student
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">

<form id="Form1" method="get" action="/Student/RemoveStudent/" runat="server">
    <label for="id">
        Student ID:
    </label>
    <input type="text" name="studentID" value="<%=HttpContext.Current.Request.QueryString["studentID"]%>" />

    <input type="submit" value="Remove Student"/>

    </form>

    <h2>Students</h2>
        <table>
          <% foreach (Student in (IEnumerable)ViewData.Model)

          { %>
         <tr>
            <td>
               <%= s.StudentID %> 
            </td>
        </tr>
          <% } %>
    </table>

</asp:Content>

Here is my controller Action:

public ActionResult Index()
{

    return View(_repository.ListAll().OrderByDescending(s => s.StudentName));
}

public ActionResult RemoveStudent(int studentId)
{

    StudentDataContext student = new StudentDataContext();

    var std = student.Students.Single(s => s.StudentID == studentId);
    student.Students.DeleteOnSubmit(std);
    student.SubmitChanges();
    return Content("Student" + studentId + " Removed");
}

Thanks in advance

  • 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-29T21:47:00+00:00Added an answer on May 29, 2026 at 9:47 pm

    For starters, you need to add the image

        <table>
          <% foreach (Student in (IEnumerable)ViewData.Model)
    
          { %>
         <tr>
            <td>
                <%= Html.ActionLink("RemoveStudent",                // Action
                                    "Students",                     // Controller
                                    new { id = Student.studentId }, // Route Args
                                    new { @class="deleteButton" }   // HTML Args
                ) %>
            </td>
            <td>
               <%= s.StudentID %> 
            </td>
        </tr>
          <% } %>
    </table>
    

    and a little css

    a.deleteButton
    {
        background: url(../Images/delete.gif) no-repeat top left;
         display: block;
         width: 50px;
         height: 50px;
         text-indent: -9999px; /* hides the link text */
    }
    

    This can be much more detailed, but you get the point. You can submit the delete via a form, pass the userID with it… etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view which lists some nodes and I want a custom output
I have an admin view which contains four foreign keys each with a few
I have some view which lists my module table entries. What is the most
I have a users table, and a view table which lists some user ids...
I'm building an asp.net MVC 2 app. I have a list view which lists
I have chat list view in which sender name should be left aligned and
i have view controller which contains a button which show the image library ,if
I have a view which is composed of top, left and bottom headers and
I have a view which was working fine when I was joining my main
I have a view which I built in Interface builder with a tableview and

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.