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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:35:36+00:00 2026-06-14T09:35:36+00:00

My scenario is that I have some HTML Dropdowns which fire jQuery on change

  • 0

My scenario is that I have some HTML Dropdowns which fire jQuery on change to dynamically populate a table of returned JSON results.

[HttpPost]
    public JsonResult GetTableInfo(Guid schemeId, Guid tableTypeId)
    {
        var tables = this.tableModel.GetTableInformationList(schemeId, tableTypeId);
        var formattedData = from t in tables
                            select new
                            {
                                TableId = t.TableId.ToString(),
                                TableName = t.TableName
                            };

        return Json(formattedData.ToList(), "text/json");
    }

The dynamic table lists filtered tables, each row dispaying the table name and a form to allow the table to be deleted. This is generated from the JSON Reults within a jQuery function “OnSuccess”

function OnSuccess(data) {
    var scheme = $('#schemesList').val();
    var tableType = $('#tableTypesList').val();
    var requestedBy = $('#requestedBy').val();

    var targetId = $('#tablesList');
    targetId.empty();
    targetId.css('color', 'black');
    if (data.length < 1) {
        targetId.append('<tr><td><strong>No tables match the selection</strong></td></tr>').css('color', 'Red');};


    for (var i = 0; i < data.length; i++) {
        var name = data[i].TableName;
        var id = data[i].TableId;
        targetId.append('<tr><td>' + name + '</td><td class="buttoncol">' +
                        '<form action="/DeleteTable" data-ajax="true" data-ajax-mode="replace" ' +
                        'data-ajax-success="OnSuccess" data-ajax-failure="OnFailure" data-ajax-update="#tablesList" ' +
                        'data-ajax-url="/GetTableInfo" method="post"> ' +
                        '<input id="tableId" name="tableId" type="hidden" value="' + id + '" />' +
                        '<input id="schemeId" name="schemeId" type="hidden" value="' + scheme + '" /> ' +
                        '<input id="tableTypeId" name="tableTypeId" type="hidden" value="' + tableType + '" /> ' +
                        '<input id="requestedBy" name="requestedBy" type="hidden" value="' + requestedBy + '" /> ' +
                        '<input type="submit" value="Delete table" id="deleteButton" /></form></td></tr>');
        if (requestedBy.length <= 0) {
            $('form input#deleteButton').attr('disabled', true);
        };
    }        
};

e.g.

My table 1 | Delete table button

My table 2 | Delete table button

My table 3 | Delete table button

…

So now what I want to be able to do is to click the delete button which posts the rows form and then once the table has been deleted get a refreshed list of the tables minus the deleted item. To achive this my DeleteTable action executesthe deletion then calls the GetTableInfo which is returns a JSONResult (this is the call that initially poplates the table).
The deletion form is setup as unobtrusive ajax such that it recalls the OnSuccess function to repopulate the table; the problem is second time round my JSON string is returned but is not being built into a table again.

I’m confused, can anyone help? Also, am I even going about this the right way? I defaulted to jquery because I couldn’t work out how to dynamically create the table contents with a Ajax.BeginForm using MVC3 tags – would appreciate any advice.

  • 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-06-14T09:35:37+00:00Added an answer on June 14, 2026 at 9:35 am

    You don’t need a form tag inside the row. Just post what you want using jquery ajax:

    for (var i = 0; i < data.length; i++) {
            var name = data[i].TableName;
            var id = data[i].TableId;
            targetId.append('<tr data-id=\'' + id + \'' ><td>' + name + '</td><td class="buttoncol">' +
                            '<input id="tableId" name="tableId" type="hidden" value="' + id + '" />' +
                            '<input id="schemeId" name="schemeId" type="hidden" value="' + scheme + '" /> ' +
                            '<input id="tableTypeId" name="tableTypeId" type="hidden" value="' + tableType + '" /> ' +
                            '<input id="requestedBy" name="requestedBy" type="hidden" value="' + requestedBy + '" /> ' +
                            '<input type="button" value="Delete table" class="deleteButton" id="deleteButton" /></td></tr>');
            if (requestedBy.length <= 0) {
                $('form input#deleteButton').attr('disabled', true);
            };
        }        
    
    $(".deleteButton").click(function (){
        var btn = $(this);
        var currentTr = btn.closest("tr");
        var tableID = currentTr.attr("data-id");
    
        $.ajax({
          type: 'POST',
          url: url,
          data: {id : tableID},
          success: function (){
             var tr = $('#tablesList tr[data-id="' + tableID +'"]');
             tr.remove();
          },
          dataType: 'JSON'
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's some easy reputation for someone. The scenario I have a table that is
So here's the scenario I have a list that loads some HTML into a
My scenario is that I have some payment transaction data in MySQL and some
Scenario: I have a view that has some DataTemplate resources <DataTemplate x:Key=myDragCueTemplate> <Border Background=Blue
Scenario I have a windows service written in C# that performs some processing based
Here is the scenario: I have a visual that displays some data The data
Problem Scripts on some pages that use jquery are not activating. Scenario Finding that
I have some JavaScript that obtains elements by ID from an HTML document. In
We have some HTML pages (local, not on a web server) that use the
I have a command line script that generates some HTML that I am trying

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.