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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:45:12+00:00 2026-06-09T14:45:12+00:00

I have a form which can have multiple values in it. For example: Please

  • 0

I have a form which can have multiple values in it.

For example:

Please list your dependants.

I have a fieldset containing my three fields

  • First name,
  • Last name,
  • Date of Birth

as well as an Add button.

My add button fires of a jQuery ajax request and upon the success adds a table row into the table

Pseudo Code:

$.ajax({
    url: myUrl,
    data: myData,
    success: function(){
        var row = $("<tr id='...'>");
        row.append("<td>").text(txtFirstName.val());
        row.append("<td>").text(txtLastName.val());
        row.append("<td>").text(dteDateOfBirth.val());
        row.appendTo($("#myDependantsTable"));
    }
    ...
});

This works great. However, now I have my HTML defined in two different places, my javascript and also in my View

IE:

<tr>
    <td>@Model.FirstName</td>
    <td>@Model.LastName</td>
    <td>@Model.DateOfBirth</td>
</tr>

A problem comes into play when I start modifying these, such as, adding a class on the date column, I need to modify the code twice.

Is there anyway around this problem?

I would like:

  • Rows to be added “ajaxy” without a postback
  • Consistent layout where I only need to make a change in one place
  • 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-09T14:45:13+00:00Added an answer on June 9, 2026 at 2:45 pm

    You could have the controller action that is called with AJAX request to return a partial view containing a row. The same partial you would use when generating your table. So instead of manipulating HTML with javascript, simply append the returned partial to the table:

    $.ajax({
        url: myUrl,
        data: { 
            // That's to bind to the view model that the controller
            // action you are invoking with the AJAX request takes
            // as parameter
            firstName: txtFirstName.val(), 
            lastName: txtLastName.val(), 
            dob: dteDateOfBirth.val() 
        }
        success: function(result) {
            $("#myDependantsTable").append(result);
        }
        ...
    });
    

    and in your markup:

    <table id="myDependantsTable">
        @foreach(var item in Model)
        {
            @Html.Partial("_Row", item)
        }
    </table>
    

    Now your controller action will return the same partial:

    public ActionResult SomeActionInvokedWithAjax(MyViewModel model)
    {
        return PartialView("_Row", model);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a form in which there can be multiple radio buttons generated dynamically
So I have a checkbox form where users can select multiple values. Then can
I have a form in which can be a few lines of inputs the
I have a form which users can add controls to and when they right
I have a form with input field which can be accessed like var algorithm
I have a form where there are 6 items, each of which can be
i have a form, which you can pretend is laid out like Windows Explorer:
I have the following form, which I have reduced as much as I can,
I have a form which has three inputs when the page loads -- 2
I have table user which have fields username,password, and type. The type can be

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.