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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:10:59+00:00 2026-05-24T20:10:59+00:00

I think I’ve got a pretty simple scenario but can’t seem to grasp how

  • 0

I think I’ve got a pretty simple scenario but can’t seem to grasp how to do it in .NET’s MVC framework. At its simplest, this is a form that has people with a ranking. I’d like to have each person’s name and a textbox next to their name listed on one page. Here’s what the (Razor) Html looks like:

@using (Html.BeginForm()) {
<fieldset>
    @foreach (var b in Model.Ballots) {
        <p>
            <label>@b.Person.FullName</label>
            @Html.TextBox("Rank")
            @Html.ValidationMessage("Rank")
        </p>
    }
</fieldset>
 <input type="submit" value="Vote" />

}

A ballot is a simple object that has a person and a ranking:

public class Ballot {
    public Person Person { get; set; }
    [Range(1, 6, ErrorMessage="The voting range is 1 through 6")]
    public int Rank { get; set; }
}

Here’s my controller’s method for handling the form submission, but it never gets called.

[AcceptVerbs("POST")]
    public ActionResult Vote(IEnumerable<Ballot> ballots) {

        return View("BallotComplete");
    }

How do I go about iterating all the models that the form submits back to the server?

  • 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-24T20:10:59+00:00Added an answer on May 24, 2026 at 8:10 pm

    I did a quick example using a Customer object, but I think it’s similar. Note how the form fields are labeled. Prefixed with name of parameter in action in controller. Index is needed to treat as a collection. Yours might be slightly more complex, because you have a nested class. (Person inside of ballot). I think by doing customers[@counter].Person.Id for form fields would work though. Sorry I didn’t have an example with ballots. 🙂

    This would be the relevant part of the View:

    @using (Html.BeginForm())
    {
        var counter = 0;
        foreach (var customer in this.Model)
         {
             <input type="text" name="customers[@counter].Id" value="@customer.Id"/>
             <input type="text" name="customers[@counter].CompanyName" value="@customer.CompanyName"/>
             counter++;
         }
         <input type="submit" />
    }
    

    and this would be the relevant part of the controller:

    public ActionResult Test()
    {
        return View(Service.GetCustomers());
    }
    
    [HttpPost]
    public ActionResult Test(Customer[] customers )
    {
        return View(customers);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I got all the steps down but I must be missing something
Think its a simple one. I am working on a site. The design is
I think this is a simple SQL query problem, but I am just not
I think this should be straightforward, but with NHibernate simple things are always the
I think http://www.webopedia.com/TERM/O/overhead.html gives a pretty good description of what programming overhead is. My
I think that asking this might be kind of silly but I'm still wondering
I think it will be very hard for you to read the code but
Think the title describes my thoughts pretty well :) I've seen a lot of
Think 2 entities OneToOne mapped. Person and Car. A Person can have a Car.
I think this has probably been asked, but after reading a lot, I'm not

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.