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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:02:54+00:00 2026-05-26T14:02:54+00:00

I use an ajax form for removing items from a list. The first time

  • 0

I use an ajax form for removing items from a list. The first time I submit something, it works but the second times, the reference of the item submitted is not correct: it is the first reference that is still used.

Here is my ajax form:

<div>
    <table>            
        @foreach (var item in Model.ProjectTechnology)
        {
            <tr>
                <td>@Html.DisplayFor(m => item.TechnologyID) </td>
                <td>@using (Ajax.BeginForm("RemoveLinkedTechnology", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "AddedTechnologies" })) { 
                    @Html.Hidden("projectID", item.ProjectID) 
                    @Html.Hidden("removedTechnologyID", item.TechnologyID) 
                    <input type="submit" value="Suppr" /> 
                    }</td>
            </tr>
        }
    </table>
</div>

Here is the action in my controller:

    [HttpPost]
    public ActionResult RemoveLinkedTechnology(int projectID, string removedTechnologyID)
    {
         // some code here...
    }

Example:

Lets say I proceed the submitting like this: first submit: AA; second submit: BB.

For the first call: removedTechnologyID contains AA.

For the second call: removedTechnologyID still contains AA.

Any idea?

Thanks

  • 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-26T14:02:55+00:00Added an answer on May 26, 2026 at 2:02 pm

    I suspect that in your controller action you are returning a partial view which updates the contents of the <table> you have shown. Now since Html helpers such as Hidden or TextBox first look for values in ModelState before binding and then in the model what happens is that @Html.Hidden("removedTechnologyID", item.TechnologyID) sees that there is a removedTechnologyID="AA" in the model state and completely ignores your model value which is item.TechnologyID. So if you have looked at the DOM after the first AJAX request you would have seen that all hidden fields have the old values inside them.

    To fix this you have 3 possibilities:

    1. Clear the item in model state in your controller action:

      [HttpPost]
      public ActionResult RemoveLinkedTechnology(int projectID, string removedTechnologyID)
      {
          ...
          ModelState.Remove("removedTechnologyID");
          ModelState.Remove("projectID");
          return View(...);
      }
      
    2. Don’t use helpers to generate the hidden fields:

      <input type="hidden" name="projectID" value="@item.ProjectID" />
      <input type="hidden" name="removedTechnologyID" value="@item.TechnologyID" />
      
    3. Write a custom Html.Hidden helper which will first use the values in the model before looking at modelstate (out of scope for this answer)

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

Sidebar

Related Questions

I am trying to use Ajax Form Submit. In the BeforeSubmit function. i want
I have a form with two places that use ajax to submit the information
I am trying to use AJAX for the first time, and I am having
A form, I use AJAX to transfer the data. The AJAX is triggered by
I have a small jQuery plugin that I use for form AJAX validation. There
I have a contact form i want to use Ajax for. My contact.php script
I have an edit form that uses an ajax form to submit to the
I want to upload an image use something like <form ...> <input type=file id=upload></input>
I have implemted AJAX form submission into my webforms before without issue but now
I'm sending AJAX form from page in http scheme to https url (the domain,

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.