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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:37:18+00:00 2026-05-13T19:37:18+00:00

I am trying to use link to submit a form using the following code:

  • 0

I am trying to use link to submit a form using the following code:

 function deleteItem(formId) {

           // submit the form

           $("#" + formId).submit(); 

       }

Basically I have a grid and it displays a number of items. Each row has a delete button which deletes the item. I then fire the following function to remove the item from the grid.

 function onItemDeleted(name) {

           $("#" + name).remove();                       

       }

It works fine when I use a submit button but when I use action link the JavaScript from the controller action is returned as string and not executed.

 public JavaScriptResult DeleteItem(string name)
        {
            var isAjaxRequest = Request.IsAjaxRequest(); 

            _stockService.Delete(name);
            var script = String.Format("onItemDeleted('{0}')", name);
            return JavaScript(script); 
        }

And here is the HTML code:

 <td>

    <% using (Ajax.BeginForm("DeleteItem",null, new AjaxOptions() { LoadingElementId = "divLoading", UpdateTargetId = "divDisplay" },new { id="form_"+stock.Name }))
       { %>

    <%=Html.Hidden("name", stock.Name)%>
   <a id="link_delete" href="#" onclick="deleteItem('form_ABC')">Delete</a>

    <% } %>

    </td>

My theory is that submit button does alter the response while the action link simply returns whatever is returned from the controller’s action. This means when using submit the JavaScript is added to the response and then executed while in case of action link it is simply returned as string.

If that is the case how can someone use action links instead of submit buttons.

UPDATE:

Seems like I need to perform something extra to make the action link to work since it does not fire the onsubmit event.

http://www.devproconnections.com/article/aspnet22/posting-forms-the-ajax-way-in-asp-net-mvc.aspx

  • 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-13T19:37:18+00:00Added an answer on May 13, 2026 at 7:37 pm

    My guess is the MS Ajax form knows how to handle a JavaScriptResponse and execute the code whereas your plain old Action link, with no relationship to the AjaxForm, does not. I’m pretty sure the MS ajax library essentially eval()s the response when it sees the content type of javascript being sent back.

    Since you have no callback in your deleteItem() method there is no place for the script to go. To fix you’ll have to manually eval() the string sent back which is considered a bad practice.

    Now I’m not familiar with the MS Ajax library to be certain of any of this but what your doing is possible. I’d do things differently but don’t want to answer with a “my way is better” approach ( especially because your blog has helped me before ) but I’d like to show this can be easier.

    I’d ditch the form entirely and use unobtrusive javascript to get the behavior you want. IN psuedo jqueryish ( don’t know ms ajax ) code:

    function bindMyGrid() {
        $('.myDeleteLink').onclicksyntax( function() {
    
             //find the td in the row which contains the name and get the text
             var nameTdCell = this.findThisCellSibling();
    
             //do an ajax request to your controller
             ajax('myUrl/' + nameTdCell.text(), function onSuccessCallback() {
    
                  //get the tr row of the name cell and remove it
                  nameTdCell.parent().remove();                 
             });
    
        });
    }
    

    This also gains the benefit of not returning javascript from your controller which some consider breaking the MVC pattern and seperation of concerns. Hope my psuedo code helps.

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

Sidebar

Ask A Question

Stats

  • Questions 330k
  • Answers 330k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, they can be overloaded based on reference or not.… May 14, 2026 at 2:31 am
  • Editorial Team
    Editorial Team added an answer Use data binding to bind the text boxes' contents to… May 14, 2026 at 2:31 am
  • Editorial Team
    Editorial Team added an answer The main bottleneck is probably disk IO and not CPU.… May 14, 2026 at 2:31 am

Related Questions

I am trying to make form elements fit into a visual style with other
I know this isn't a unique issue but I've not had much luck finding
I'm wondering if it's possible to capture details from the web page that a
I'm currently in the process of learning ASP MVC and am running into a
I have the following code that i am trying to change from a regular

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.