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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:32:51+00:00 2026-06-16T22:32:51+00:00

I have created a list of items from a database. These are shown correctly.

  • 0

I have created a list of items from a database. These are shown correctly. Now i would like to save the changed booleans to my database. How can I receive all these items to my controller so i can loop through them by foreach or something?

CONTROLLER

public class ItemController : Controller
{
    private SocialGEOContext db = new SocialGEOContext();
    public ActionResult ApproveItems()
    {
        Utility ut = new Utility();
        IEnumerable<Item> items;
        items = ut.GetAllDistrictItems();
        return View(items);
    }

    [HttpPost]
    public ActionResult ApproveItems( ??? )
    {
        ???
    }

In the HttpPost i tried

    [HttpPost]
    public ActionResult ApproveItems( IEnumerable<Item> ViewItems )
    {
        foreach (Item item in ViewItems)
        {
            var testje = item.ItemTitle;
        }
        return View();
    }

But the ViewItems is empty

PAGE

@model IEnumerable<LibModels.Item> 
@{
    ViewBag.Title = "ItemsByDistrict";
}

<h2>All items from district</h2>



@using (Html.BeginForm()) {
  @Html.ValidationSummary(true)
    <fieldset>
        <table>
        @foreach (var item in Model) {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.ItemID)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ItemTitle)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ItemCreateddate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ItemDescription)
                </td>
                <td>
                    @Html.EditorFor(modelItem => item.ItemApproved)
                </td>
            </tr>
        }
        </table>

        <p>
            <input type="submit" value="Edit" />
        </p>
    </fieldset>
}
  • 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-16T22:32:52+00:00Added an answer on June 16, 2026 at 10:32 pm

    You need to use a for loop in order for the model binding to work

    @for(int i; i < Model.Count; i++) {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => modelItem[i].ItemID)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => modelItem[i].ItemTitle)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => modelItem[i].ItemCreateddate)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => modelItem[i].ItemDescription)
                    </td>
                    <td>
                        @Html.EditorFor(modelItem => modelItem[i].ItemApproved)
                    </td>
                </tr>
            }
    

    See this article for a good breakdown on model binding collections

    Note: you’ll need to call ToList() on the model so that you can use indexing

    In other words in your action method:

    public ActionResult ApproveItems()
        {
            Utility ut = new Utility();
            IEnumerable<Item> items;
            items = ut.GetAllDistrictItems();
            return View(items.ToList());
        }
    

    And then change the model in the view:

    @model IList<LibModels.Item> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dynamically created list. Items from the list should be able to
I have a list of items that are created from the results of website
I have created a list view that displays the names and dates of items
I have created a TableView(Grouped Table View). And I can list the items in
I have a simple unordered list with list items as menu item i created
I am new to EF. I created entity models from database. I have tables
I have an unordered list with no list items. I get some information from
In my app I have created a List of items which are displayed on
I have a list of items. When I create the list each item has
I want to create a marketplace where users can list items and have buyers

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.