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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:07:26+00:00 2026-06-13T13:07:26+00:00

I have a list that I would like to group and edit within a

  • 0

I have a list that I would like to group and edit within a razor view.

If the POCO is:

public class FooBar {

public string GroupName {get;set;}
public string SomeValue {get;set;}

// etc.

}

And the model in the View:

@model IEnumerable<FooBar>

And the Post action is like this:

[HttpPost]
        public ActionResult FooBarPost(IEnumerable<FooBar> model)

Normally to edit a list I would use this syntax in my view:

@Html.EditorForModel()

Which works great, it creates lovely little inputs like:

<input id="[0].SomeValue" />

And the post back is perfect.

Now if I want to change my view to the much less awesome:

<fieldset>
                        <legend>Legendary</legend>
                        @foreach (var group in Model.GroupBy(x => x.GroupName))
                        {
                            <h3>@group.Key</h3>

                            @Html.EditorFor(x => group)
                        }
                    </fieldset>

Then when I post my list comes back as null?

I remember there being a trick to fixing this, I just can’t remember what it was?

Thanks.

Edit:

added [Bind(Prefix="group")] to my action which now brings back just one of the input values.

I noticed the HTML generated looks like this (all on same page):

Group 1:

<input id="group_0__SomeValue" name="group[0].SomeValues" type="hidden" value="bla">  
<input id="group_1__SomeValue" name="group[1].SomeValues" type="hidden" value="bla">

Next group:

<input id="group_0__SomeValue" name="group[0].SomeValues" type="hidden" value="bla">
  • 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-13T13:07:27+00:00Added an answer on June 13, 2026 at 1:07 pm

    Assuming your goal is to render an editor for each unique instance of GroupName, change your code to look like the following:

    @model IEnumerable<PlayMvc.Models.FooBar>
    <fieldset>
        <legend>Legendary</legend>
        @using(Html.BeginForm("Test","Home", FormMethod.Post)){
            var groups = Model.GroupBy(x => x.GroupName).Select(x => x.First()) .ToList();
            for (int i = 0; i < groups.Count(); i++ )
            {
                <h3>@groups[i].GroupName</h3>
    
                @Html.EditorFor(x => groups[i])
            }
            <input type="submit" />
        }
    </fieldset>
    

    On your controller side do something as this:

    public ActionResult Test([Bind(Prefix="groups")]List<FooBar> model)
    

    Sidenote

    Don’t use foreach when trying to work with enumerables to render items in the view, otherwise they will not have an indexer in the name. @Html.EditorFor(x => groups[i]) and @Html.EditorFor(x => group) would render different name tag in HTML, so model binder wouldn’t recognize it as part of a collection that it should reconstruct as input for your action.

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

Sidebar

Related Questions

I have a list of files that I would like analyze. They are all
I have a List of objects that I would like to convert to a
Let's say I have a list of domain names that I would like to
I have a list of thumbnails. They have fixed size. I would like that
I have created a repeat control that list some documents. I would like to
I have a script that sends emails to a contact list. I would like
We have a SharePoint solution that uses a standard task list. We would like
I have a list of image paths in my PHP script that I would
I have a list that looks like this: l1 = ['200:200', '90:728'] I have
I have configured my list so that users can only read and edit items

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.