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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:57:07+00:00 2026-05-23T03:57:07+00:00

How I need to send the data from the client in order to get

  • 0

How I need to send the data from the client in order to get it in Save action?

Mean while the contacts list I get in Save action is null.
I checked fiddler and it sends id=1&address=a&id=2&address=b. I realize that I need to do something in order that MVC will “understand” that there are 2 different records.

What is done, in practice, in this case?

// Action in ContactController
public ActionResult Save(List<Contact> contacts)
{
     ...
}  

public class Contact
{
    public int Id {get;set;}
    public string Address{get;set;}
}


// View
<div id="contacts">
    <% for(i=0;i<3;i++) { %>
       <input name=<%= list[i].id %> type="text" />
       <input name=<%= list[i].address %> type="text" />
   <% } %>
</div>


<script type="text/javascript">
     var postData = $("#contacts").serialize();
     $.ajax({
             type: "POST",
             url: url,
             data: postData,
             async: false,
             success: function () { ... }
     });  
</script>
  • 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-23T03:57:08+00:00Added an answer on May 23, 2026 at 3:57 am

    I would recommend you to use editor templates in your view instead of writing some for loops:

    For example:

    public ActionResult Save()
    {
        var model = Enumerable.Range(1, 3).Select(x => new Contact());
        return View(model);
    }
    
    [HttpPost]
    public ActionResult Save(List<Contact> contacts)
    {
        ...
    }
    

    and in the view (which is strongly typed to IEnumerable<Contact>):

    <div>
        <% using (Html.BeginForm()) { %>
            <%= Html.EditorForModel() %>
            <input type="submit" value="OK" />
        <% } %>
    </div>
    

    and inside the contact editor template (~/View/Shared/EditorTemplates/Contact.ascx):

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<Contact>" 
    %>
    <%= Html.TextBoxFor(x => x.Id) %>
    <%= Html.TextBoxFor(x => x.Address) %>
    

    Editor templates will ensure to generate proper names for the input fields.

    Now all that’s left is AJAXify the form:

    $('form').submit(function() {
        $.ajax({
            url: this.action,
            type: this.method,
            traditional: true,
            data: $(this).serialize(),
            success: function(result) {
                ...
            }
        });
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to send large binary(2Gb-10Gb) data from one pc(client) to another pc(server) over
I need send certain attributes(say, human readable user name) from server to client after
I am trying to send data from my RESTful client to my RESTful server.
I have a requirement where I need to send some data from my server
I would like to send data from a server to a client, continuously (streaming),
I want to send data of bytes from .net server to flash client. i
I need to send data to a hardware device over serial port. I'm using
I have an html form. I need to send its data to flash on
I need to send and receive data over serial connections (RS-232 and RS-422). How
I am calculating 16 bit checksum on my data which i need to send

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.