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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:25:27+00:00 2026-05-30T13:25:27+00:00

I am currently baffled to why my method is not running. I placed a

  • 0

I am currently baffled to why my method is not running. I placed a breakpoint on it because I suspect some failure to occur somewhere.

Here is my explanation:

I just started a new ASP.NET MVC 2 application. I Connected my Home/Index page to a new strongly-typed view which I have created called Categories/List. Everything Displays fine – the categories are retrieved from my Entity Data model and placed on the page. I removed the “Details” link which is automatically created with the view.

Afterwards, I added a strongly Typed Delete View to Categories/Delete. In my CategoriesController, I have the following code (Which works)

      <%: Html.ActionLink("Delete", "DeleteCategory", new { id=item.CategoryID })%>

to:

    /// <summary>
    /// Get rid of a Category
    /// </summary>
    /// <returns>Redirect to ~/Categories/Delete</returns>
    public ActionResult DeleteCategory(int id)
    {
        ViewData.Model = (from c in DataContext.Categories where c.CategoryID == id select c).FirstOrDefault();
        return View("Delete");
    }

My Delete View Looks like this:

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

Delete

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
    <legend>Fields</legend>

    <div class="display-label">CategoryID</div>
    <div class="display-field"><%: Model.CategoryID %></div>

    <div class="display-label">Category1</div>
    <div class="display-field"><%: Model.Category1 %></div>

</fieldset>
<% using (Html.BeginForm()) { %>
    <p>
        <input type="submit" value="Delete" /> |
        <%: Html.ActionLink("Back to List", "List") %>
    </p>
<% } %>

Ok. This will all seem familiar to MVC Experts. Mind, I just started with MVC and I do not have Extremely good knowledge with Linq Either, so I am expecting some flaming from my following Code (Which doesn’t even run – the purpose of the question – I don’t know why it does not run!)

It is in my categoriesController

    [HttpPost]
    public ActionResult Delete(Models.Category category)
    {
        foreach (Models.Category c in DataContext.Categories)
        {
            if (c.CategoryID == category.CategoryID)
            {
                DataContext.Categories.DeleteObject(c);
            }
        }
        DataContext.SaveChanges();

        return RedirectToAction("List", "List", "Categories");
    }

Any Ideas as to why my code refuses to run? I breakpointed at the first brace. Breakpoint never gets reached.

  • 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-30T13:25:28+00:00Added an answer on May 30, 2026 at 1:25 pm

    The problem is that your GET action (DeleteCategory) doesn’t have the same as your POST action (Delete).

    So you need to specify the action you want to invoke:

    <% using (Html.BeginForm("Delete", "Categories")) { %>
    

    Or if you don’t want to do that you should rename your GET method to be he same as the POST method:

    // Access this action with /Categories/Delete
    public ActionResult Delete(int id)
    {
        var model = DataContext.Categories.FirstOrDefault(x => x.CategoryID == id);
        return View(model);
    }
    
    [HttpPost]
    public ActionResult Delete(Category category)
    {
        ...
    }
    

    Now since both your GET and POST actions are named the same way, you could use the BeginForm helper without arguments because the distinction between those actions will be based on the HTTP verb used to invoke them:

    <% using (Html.BeginForm()) { %>
    

    As a side note inside your form you don’t have any input field. So don’t expect to get anything out of this Category that your POST action expects. You might need to at least include a hidden field containing the id of the category that you are willing to delete.

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

Sidebar

Related Questions

Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
Currently I'm doing some unit tests which are executed from bash. Unit tests are
Currently I am borrowing java.math.BigInteger from the J# libraries as described here . Having
I have been trying to find answers to this question, and I'm currently baffled.
I'm currently developing a VSPackage, and it will have some log-in functionality external to
I'm currently completely baffled by the problem I'm having. I'm writing a plug-in for
Currently my workflow with Emacs when I am coding in C or C++ involves
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently we have a project with a standard subversion repository layout of: ./trunk ./branches
Currently, I am writing up a bit of a product-based CMS as my first

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.