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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:19:01+00:00 2026-05-28T07:19:01+00:00

I have written a partial view that displays a list of rows, where some

  • 0

I have written a partial view that displays a list of rows, where some fields in the row are editable using a textbox, checkbox, or whatever.

I would like the parent view to have a “submit” button that posts the whole collection of updated rows so that I can do a group update rather than posting once for every updated row.

Here’s what I have:

public class GroupModel {
  public string SomeGenericProperty { get; set; }
  public IEnumerable<ItemModel> Items { get; set; }
}

public class ItemModel {
  public long ID { get; set; }
  public string Field1 { get; set; }
  public string Field2 { get; set; }
}

Then I have a view “GroupDetails”:

@model MyNamespace.GroupModel
...
@using (Html.BeginForm("SaveItems", "Home")) {
  <fieldset>
  ...
  @Html.Partial("ItemList", Model.Items)
  ...
  <input type="submit" value="Approve" />
  </fieldset>
}

And a partial view “ItemList”:

@model IEnumerable<MyNamespace.ItemModel>
<table>
  <tr>
    <th>
      &nbsp; Field 1 &nbsp;
    </th>
    <th>
      &nbsp; Field 2 &nbsp;
    </th>
    <th>
    </th>
  </tr>
  @foreach (var item in Model) {
    <tr>
      <td>
        &nbsp;
        @Html.TextBoxFor(modelItem => item.Field1)
        &nbsp;
      </td>
      <td>
        &nbsp;
        @Html.TextBoxFor(modelItem => item.Field2)
        &nbsp;
      </td>
      <td>
        @Html.HiddenFor(i => item.ID)
      </td>
    </tr>
  }
</table>

But when I post, the information from partial view is not being posted; the GroupModel object’s Items property is null.

What’s the right way to do this?

  • 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-28T07:19:02+00:00Added an answer on May 28, 2026 at 7:19 am

    I would recommend you to always use editor templates. The reason your code doesn’t work is because you used a partial and this partial doesn’t inherit the parent template context which means that helpers that are used inside it will generate wrong names for the input fields.

    For example if you look at the source code of your page you will see this:

    <td>
        &nbsp;
        <input type="text" name="[0].Field1" id="[0]_Field1" />
        &nbsp;
    </td>
    

    instead of the correct name which is:

    <td>
        &nbsp;
        <input type="text" name="Items[0].Field1" id="Items[0]_Field1" />
        &nbsp;
    </td>
    

    I would recommend you reading the following blog post to better understand the wire format that the default model binder expects.

    So start by fixing your main view first and replace the partial with an editor template:

    @model MyNamespace.GroupModel
    @using (Html.BeginForm("SaveItems", "Home")) 
    {
        <fieldset>
            ...
    
            <table>
                <thead>
                    <tr>
                        <th>&nbsp; Field 1 &nbsp;</th>
                        <th>&nbsp; Field 2 &nbsp;</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @Html.EditorFor(x => x.Items)
                </tbody>
            </table>
    
            ...
            <input type="submit" value="Approve" />
        </fieldset>
    }
    

    and then define a custom editor template that will be rendered for each element of the model (~/Views/Shared/EditorTemplates/ItemModel.cshtml – this works by convention, it should be either inside ~/Views/Shared/EditorTemplates if you want it to be reused among controllers or inside ~/Views/Home/EditorTemplates if you want this template to be available only for the Home controller – and the name of the template must be the type of the collection – in your case it is ItemModel.cshtml):

    @model MyNamespace.ItemModel
    <tr>
        <td>
            &nbsp;
            @Html.TextBoxFor(x => x.Field1)
            &nbsp;
        </td>
        <td>
            &nbsp;
            @Html.TextBoxFor(x => x.Field2)
            &nbsp;
        </td>
        <td>
            @Html.HiddenFor(x => x.ID)
        </td>
    </tr>
    

    Now everything will bind fine and dandy in your controller action:

    [HttpPost]
    public ActionResult SaveItems(GroupModel model)
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a very simple CTE expression that retrieves a list of all
I have written a function that sorts a big scale of data. To test
I have written a function that extract the domain from hostname. e.g. www.domain.com ->
I have written some Python scripts in Eclipse where at some point I have
I have a set of request specs written using RSpec2 and Capybara. Here's one
I have written a very small C# program, that uses a very small SQL
In my application (written in c#) I have a textbox and a submit button.
I have followed the blog post written by Steve Sanderson at blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc . It
I have written a code that searches specific string from database table.what i want
I have written a function that gets a given number of random records from

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.