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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:40:32+00:00 2026-06-18T07:40:32+00:00

I am passing a list from my controller to my view, and then inside

  • 0

I am passing a list from my controller to my view, and then inside a form I loop through each list item and display a table with some textboxes that need to be filled in for each item.

What I then want to do is submit the data back to my controller, look through it to grab the results of what was entered, and save to database.

How do I do this?? I have put my code below

CONTROLLER

public ActionResult GetListOfDogs()
{
var list = db.dogs;  //gets multiple dogs 
return View(dogs);

///Dog object looks like this
///int Id 
///string DogName 
///string RegNumber 
///string Breed 
}

[HttpPost]
public ActionResult SaveDogInfo(string[] RegNumber, string[] Breed)
{

}

VIEW

GetListOfDogs.cshtml

@model Dog

@using(Html.BeginForm("SaveDogInfo", "Dog", FormMethod.Post))
{
<table>
    <tr>
        <th>Name</th>
        <th>Reg Number</th>
        <th>Breed</th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>@item.DogName</td>
            <td>@Html.TextBox("RegNum", null, new{id = "dId_=" + @item.Id})</td>
            <td>@Html.TextBox("Breed", null, new{id = "breed_=" + @item.Id})</td>
        </tr>
    }
</table>
<input type="Submit" value="Save" />

}

Inside my ‘SaveDogInfo’ action, I can view the results for RegNumber and Breed, but there is no id coming back with them, so I have no way of matching the result with the actual DogId it belongs to..

Can anyone help or am I just totally missing the point???

Cheers
Chris

  • 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-18T07:40:33+00:00Added an answer on June 18, 2026 at 7:40 am

    Your model of your view should be something enumerable, no ?

    @model IList<Dog>
    

    then use a for loop, and add an hidden field for Id. !

    @for (var i = 0; i < Model.Count(); i++) 
        {
            <tr>
                <td>@Html.DisplayFor(m => Model[i].Name</td>
                <td>@Html.TextBoxFor(m => Model[i].RegNumber)</td>
                <td>
                    @Html.TextBoxFor(m => Model[i].Breed)
                    @Html.HiddenFor(m => Model[i].Id)
               </td>
            </tr>
        }
    

    then your post action should become

    [HttpPost]
    public ActionResult SaveDogInfo(IEnumerable<Dog> dogs)
    {
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am passing a list to the view from Controller. How can i generate
From my controller I am passing a list called ccdata through JSON. It only
AFAIK, there are two ways of passing data to the view from controller :
Hi i'm passing a List object from my controller to Javascript where it is
I have a list of categories and sub categories which is passing from controller
I am passing an object from the controller to the view. The object contains
I'm passing from my view page one to five images to controller. <input type=file
I'm having trouble with ASP.NET MVC and passing data from View to Controller. I
I m trying to get a list of radiobuttons from the controller and display
In Edit view: I am passing ViewBag list for the ddl Controller: ViewBag.CountryList =

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.