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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:29:37+00:00 2026-06-10T14:29:37+00:00

I have a view where I add some elements to a table from Database;

  • 0

I have a view where I add some elements to a table from Database; let’s call the table Students. On the view I also have the option to assign to the student I am adding to the table some books . I have done this with Ajax.

Demo:

    Name of Student: ...
    Books : <here is a drop down> ( from database)    < here is a button> (add button)

    <ul>
   When I click the button here I append some books. I also retain on Session the id of every book ( in a list and when I click submit I send that list to the server )
    </ul>
[Submit button]

The problem is that I want to add a delete buton too like this :

    Name of Student: ...

    Books : <here is a drop down>     < here is a button> 

    <ul>
    Book1  delete
    Book2  delete
    </ul>
[Submit button]

And when I click the delete button to remove that element from the list and from the Session.

Here is my code:

  • Script from the View

    $(function () {
    
        $("#add").click(function () {
    
            //items.push($("#category").val());
            $.ajax({
                url: '@Url.Action("AddCategory")',
                type: "POST",
                dataType: "JSON",
                data: { id: $("#categoryId option:selected").val() },
                beforeSend: function () { },
                success: function (data) {
    
                    $("#toFill").append("<li>" + $("#categoryId option:selected").text() + " " + "<span style='cursor:pointer;' id='a'>" + "[X]" + "</span>" + " " + "</li>");
                },
                error: function () { alert("error") }
    
            })
            $("#toFill #a").click(function () {
    
                $.ajax({
                    url: '@Url.Action("DeleteCat")',
                    type: "POST",
                    dataType: "JSON",
                    data: { id: $("#categoryId option:selected").val() },
                    beforeSend: function () { },
                    succes: function (data) {
                        // $("li").remove();
                        alert("lala"); return false;
                    },
                    error: function () { alert("error at delete") }
    
    
    
                })
    
            });
        })
    
  • AddCategory and DeleteCat from Controller:

    public ActionResult AddCategory(int id)
    {
        Session.Category.Add(id);
        return Json(id, JsonRequestBehavior.AllowGet);
    }
    
    public ActionResult DeleteCat(int id)
    {
        Session.Category.Remove(id);
        return Json(id, JsonRequestBehavior.AllowGet);
    }
    
  • 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-06-10T14:29:39+00:00Added an answer on June 10, 2026 at 2:29 pm

    It will be more logical and easier to follow, use and program if you have one delete button acting on the drop down directly – i.e. select an item in drop down and click delete to delete the selected item.

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

Sidebar

Related Questions

In my iPhone app I have a table view where I add a tick
I have to list several elements that are coming from a database source A
I have a grid view and I add columns to it by code: //Retrieve
I have a list view comprised of the following: // Add column headers for
I have the following view that allows a user to add a review for
So I have a viewControllerA, and I want to add another View managed by
I have created a Dynamic View Panel custom control and want to add a
I have an code segment of view .cshtml page like : @Html.ActionLink(Add Charts of
I have a form in witch users can add their working hours view them
I have folders and pages /admin/add/index.php, /admin/edit/index.php & /admin/view/index.php which all are requiring page

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.