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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:28:45+00:00 2026-05-18T05:28:45+00:00

// GET: /Product/Delete/5 public ActionResult Delete(int id) { var res = (from r in

  • 0

// GET: /Product/Delete/5

    public ActionResult Delete(int id)
    {
        var res = (from r in data.Products where r.ProductID == id select r).FirstOrDefault();
        //return View(data.Products.FirstOrDefault(p => p.ProductID == id));
        return View(res);
    }

    //
    // POST: /Product/Delete/5
   // [HttpPost]
   [AcceptVerbs(HttpVerbs.Post)]
    **public ActionResult Delete(Product producttodelete)**
    {

        try
        {
            // TODO: Add delete logic here
            var res = (from r in data.Products where r.ProductID == producttodelete.ProductID select r).FirstOrDefault();
           // var productto = data.Products.Single(p => p.ProductID == producttodelete.ProductID);
            data.Products.DeleteObject(res);
            data.SaveChanges();
            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }
}

Here in the line “producttodelete” i am not getting any values it is cuming null.Rather than create,details,edit are working fine…. only delete not working…….I tried a lot

  • 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-18T05:28:46+00:00Added an answer on May 18, 2026 at 5:28 am

    Assuming you are using strongly typed views, have you tried:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Delete(int id, Product productToDelete)
    {
        try
        {
            var res = (from r in data.Products where r.ProductID == id select r).FirstOrDefault();
            data.Products.DeleteObject(res);
            data.SaveChanges();
            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }
    

    … or if you are not using strongly typed views:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Delete(int id, FormCollection collection)
    {
        try
        {
            var res = (from r in data.Products where r.ProductID == id select r).FirstOrDefault();
            data.Products.DeleteObject(res);
            data.SaveChanges();
            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }
    

    In either case, you need to provide an id parameter which you can then use to get your object from your datastore. The default route mapping in MVC2 (in Global.asax.cs) will take the ID from the post URL and map it to this parameter for you.

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

Sidebar

Related Questions

Given the following object: public class Product { string Name {get;} int Quantity {get;}
I have the following .Net class: public class Product { public int ID {get;set;}
How can I get the list of cross product pairs from a list of
Does anyone knows how i can get buyer's reviews from a Product in a
I would like to delete the ICollection PriceBreaks from Product. I'm using the following
I'd like to do GET /Product/1 and DELETE /Product/1 instead of having to have
I have the following MySQL query: DELETE FROM catalogue WHERE catalogue_id IN ( SELECT
I am developing an app which uses barcode to get the product information of
I have 2 equal-length lists and I am trying to get scalar product of
Now, i want to get all product ID of my site. IS there a

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.