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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:25:53+00:00 2026-06-17T20:25:53+00:00

—EDIT— I have this model public class MainModel { string Name; List<Address> Addresses; }

  • 0

—EDIT—

I have this model

public class MainModel {
  string Name;
  List<Address> Addresses;
}

public class Address {
  string prop2;
}

Is quite easy to create the view but I didn’t find a way to bind it in the POST request. I would like to avoid to loop on Request.Form

View

  @foreach (var obj in Model.Address)
  {
    <tr>
      <td>            
        <input type="text" id="@string.Format("obj.Name.{0}", obj.Id)" name="@string.Format("obj.Name.{0}", obj.Id)" value="@Model.Name" />
        //I'm not able to overwrite the name attribute, still working on that
      </td>
    </tr>
  }

Is there a way to automatically bind this list in the ActionController? Something like

public ActionResult Edit(MainModel model, List<Address> objects)

I suppose I have to create a custom model binding but I don’t find the way to do it

… MVC make us lazy … 🙂

  • 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-17T20:25:54+00:00Added an answer on June 17, 2026 at 8:25 pm

    From reading you’re requirements you may be over thinking the solution.

    In the Views/EditorTemplates folder create a view Address.cshtml similar to

    @model SampleMvc.Models.Address
        <tr>
            <td>
                @Html.HiddenFor(x=>x.Id)            
                @Html.TextBoxFor(x=>x.Prop2)
            </td>
        </tr>
    

    In your Edit view have markup similar to:

    @using (Html.BeginForm()) {
        <table>
            @Html.EditorFor(x=>x.Name)
            <br/>
            <table>
                @Html.EditorFor(x=>x.Addresses)
            </table>
        </table>
        <input type="submit" id="submit" value="Submit"/>
    }
    

    The EditorFor statement will use the Address editor template to render the mark up.

    If you need the ability to add new addresses you can use client side scripting to find the highest id and inject the following mark up

    <tr>
       <td>
          <input id="Addresses_{HIGHESTIDVALUEHERE}__Id" type="hidden" value="{HIGHESTIDVALUEHERE}" name="Addresses[{HIGHESTIDVALUEHERE}].Id" data-val-required="The Id field is required." data-val-number="The field Id must be a number." data-val="true">
    <input id="Addresses_{HIGHESTIDVALUEHERE}__Prop2" type="text" value="" name="Addresses[{HIGHESTIDVALUEHERE}].Prop2">
       </td>
    </tr>
    

    Then you controller action becomes

    public ActionResult Edit(MainModel model){
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is what I'm doing: public static String htmlToText(String inString) { String noentity=StringEscapeUtils.unescapeHtml(inString); return
I have set of xml elements like this: <item code=<HTML_CODE> /> For example: <items>
I basically have the classic many to many model. A user, an award, and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm including a local class that requests a file from a remote server. This
string formIdList = 8256, 8258, 8362, 8120, 8270, 8271, 8272, 8273, 8257, 8279, 8212,
This is an interesting problem that I have searched here and all over my
I have a directory structure like this: node_modules/mymodule/index.js : module.exports = require('./lib/mymodule'); node_modules/mymodule/lib/mymodule.js var
I have read and added a question to this thread http://code.google.com/p/fullcalendar/issues/detail?id=143 but its a
I have the following file: BTA Pos KLD 4 79.7011 5.7711028907 4 79.6231 5.7083918219

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.