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

  • Home
  • SEARCH
  • 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 3939532
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:18:39+00:00 2026-05-20T00:18:39+00:00

I have a custom HtmlHelper; public static MvcHtmlString DeleteEmployeeOtherLeave(this HtmlHelper html, string linkText, Leave

  • 0

I have a custom HtmlHelper;

public static MvcHtmlString DeleteEmployeeOtherLeave(this HtmlHelper html, string linkText, Leave _leave)
{
    string url = string.Format("/Payroll/Delete?_employeeOtherLeaveId={0}", _leave.LeaveId.ToString());
    return html.RouteLink(linkText, "Default",
        new { _employeeOtherLeaveId = _leave.LeaveId, action = "Delete" },
        //new { @class = "delete-link" }
        new { onclick = "$.ajax({url: this.href, type: 'DELETE', success: function(result) {$('#wholepage').html(result);}}); return false;" }
}

As you can see I have a long string for my onclick event for my RouteLink command.
I want to put this in some unobtrusive Javascript, and then put in some extra javascript for a confirmation popup.
So if I comment out the onclick event and uncomment out the class, I intend to use instead the following Javascript function

$('#delete-link').click(function () {
    var flag = confirm('Are you sure you wish to delete this item?');
    if (flag == true) {
        $.ajax({
            url: this.href,
            type: 'DELETE',
            success: function (result) {
                // update some DOM element with the result returned by the
                // server. So supposing that you have some <div id="someContainer">
                // that will contain the part of the DOM you want updated:
                $('#wholepage').html(result);
            }
        });
    }
    return false;
});

The problem then is that a get the error;
System.Web.HttpException: A public action method ‘Delete’ was not found on controller ‘SHP.Controllers.PayrollController’

But this is a public method, so why should I get that?

    [AcceptVerbs(HttpVerbs.Delete)]
    public ActionResult Delete(int _employeeOtherLeaveId)
    {
        EmployeeOtherLeaf.Delete(_employeeOtherLeaveId);
        return RedirectToAction("Payroll");
    }

Some people have pointed out that this.url will have the wrong value. This appears to be the case, Firebug it reports that this.href is undefined.
So I change the helper method as below;

  public static MvcHtmlString DeleteEmployeeOtherLeave(this HtmlHelper html, string linkText, Leave _leave)
    {
        string url = string.Format("/Payroll/Delete?_employeeOtherLeaveId={0}", _leave.LeaveId.ToString());
        return html.RouteLink(linkText, "Default",
            new { _employeeOtherLeaveId = _leave.LeaveId, action = "Delete" },
            new { onclick = "DeleteRow('" + url + "')" }
     }

The javascript function looks like this;

function DeleteRow(url) {
    $.ajax({
        url: url,
        type: 'DELETE',
        success: function (result) {
            $('#wholepage').html(result);
        }
    });
    return false;
}

I still get the same error.

  • 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-20T00:18:40+00:00Added an answer on May 20, 2026 at 12:18 am

    Your issue is that jQuery does not support making Delete calls via Ajax so it is doing a GET or a POST which is not found on the controller because you are restricting to delete.

    See here on how to solve this issue:

    http://homework.nwsnet.de/news/9132_put-and-delete-with-jquery

    Hope this helps

    Addition:

    I have looked into this more and the latest jQuery may support it but states:

    type String Default: ‘GET’ The type of
    request to make (“POST” or “GET”),
    default is “GET”. Note: Other HTTP
    request methods, such as PUT and
    DELETE, can also be used here, but
    they are not supported by all
    browsers.

    The way that MVC gest around flakey browser support is to add a hidden field to forms that delete called _method and give it a value of delete

    So you may wish to add to your ajax code:

    $('#delete-link').click(function () {
        var flag = confirm('Are you sure you wish to delete this item?');
        if (flag == true) {
            $.ajax({
                url: this.href,
                data: {_method: "delete"},
                type: 'POST',
                success: function (result) {
                    // update some DOM element with the result returned by the
                    // server. So supposing that you have some <div id="someContainer">
                    // that will contain the part of the DOM you want updated:
                    $('#wholepage').html(result);
                }
            });
        }
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently stuck with this problem of displaying an image using HtmlHelper class.
I have custom server control contains templatefield when an out button clicked the field
I have custom components which must adjust their text content based on space constraints.
I have custom upload control. The control has gridview with the uploaded documents and
I have custom view in my application which can be scrolled by the user.
I have custom validators and filters that I have created that I would like
Would anyone be able to advise if it’s possible to re-use an existing HtmlHelper
I'm trying to understand how to build a self referencing model for hierachical data.
We began a project using WebForms, and developed a somewhat complex portal system to
I've starting programming on ASP.NET MVC Framework a year ago. Recently. I've learning Ruby

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.