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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:10:58+00:00 2026-06-17T09:10:58+00:00

My scenario is much complicated so i simplified it with the example below. The

  • 0

My scenario is much complicated so i simplified it with the example below. The main problem is binding collection properties of a model, specifying the path of the property like Html.TextBox("List[0].Name") and not the Html.TextBoxFor(t => t.List[0].Name). So, for the current view i will only know some of the metadata of the model so i will have to construct it this way. Here is the scenario :

Model

public class ModelTest
{
    public int Id {get;set;}
    public List<Foo> Collection {get;set;}
}

public class Foo
{
    public string Value1 {get;set;}
    public string Value2 {get;set;}
}

Controller

public class TestController: Controller
{
    [HttpGet]
    public ActionResult Test()
    {
        var model = new ModelTest()
        {
            Id = 455,
            Collection = new List<Foo>()
            {
                new Foo(){ Value1 = "sagasga", Value2 = "Beul"},
                new Foo(){ Value1 = "dgdsgds", Value2 = "fhfhd" }
            }
        };
        return View(model);
    }

    [HttpPost]
    public ActionResult Test( ModelTest model)
    {
        //....
        return View();
    }

View:

@using (Html.BeginForm())
{
    @Html.TextBox("Id")
    @Html.TextBox("Collection[0].Value1")
    @Html.TextBox("Collection[0].Value2")
    <input type="submit" value="Add" />
}

For the code above i get empty textboxes for the collection values. However, when the page is submited i get the model built correct in the Post method.

Many thanks,
Alex

  • 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-17T09:10:59+00:00Added an answer on June 17, 2026 at 9:10 am

    This is the way to name you input fields when you wanna post a collection to your controller. However, you have to specify the initial value yourself. Your code is currently just creating textbox with the name property set to Collection[0].Value1. You still need to specify the input this way,

    @Html.TextBox("Collection[0].Value1", Model.Collection.FirstOrDefault().Value1)
    @Html.TextBox("Collection[0].Value2", Model.Collection.FirstOrDefault().Value2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was expecting the below scenario common, but couldn't find much help online. I
The following scenario pretty much sums up my problem: Scenario: problems with subprocesses Given
Scenario : I'll try to put an analogy with the loan broker example from
I received a long Fiddler trace (with a complicated scenario) and need to correlate
I have an expense tracking iOS Application using Core Data Model: Scenario: -> An
Here is my scenario. I'm am HTML/CSS guy, JavaScript not so much. But this
The scenario in question relates to the much-maligned Microsoft Jet database engine . The
I probably want too much, but my scenario is public dynamic CreateConfigObject(JobConfigurationModel config) {
I'm trying to implement the folowing scenario, using JQuery deferred, without much luck. What
Scenario & Problem description : User request file to server File is big so

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.