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

  • Home
  • SEARCH
  • 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 3975136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:38:57+00:00 2026-05-20T04:38:57+00:00

I have a complex view model which contains a collection of other objects which

  • 0

I have a complex view model which contains a collection of other objects which are recursively rendered using editor and display templates.

Each of the items in the collection contains a form model that I would like to submit to a controller. Note, that I do not want to post the whole view model back again, just the form model.

My problem is that MVC renders each object as part of a collection, and I do not know how to bind a single object from the collection to an object in the controllers signature.

I know I can bind the whole lot back again using IEnumerable<Account>, but I am trying to create row level submissions rather than the whole page.

If anyone can point me in the right direction, or show me how this should be done in the MVC world (I come from web forms so have been somewhat spoiled) I’d appreciate it immensely.

I’ve included an example HTML fragment below and also the controller I would like to post to.

<form action="/Home/Index" method="post">
    <input id="Accounts_0__AccountName" name="Accounts[0].AccountName" type="text" value="Account 1" />
    <input id="Accounts_0__AccountId" name="Accounts[0].AccountId" type="hidden" value="dddf5ca7-f8de-4192-b63a-3548f891e293" />
    <input type="submit" value="Submit" />    
</form>                  

<form action="/Home/Index" method="post">
    <input name="Accounts[1].AccountName" type="text" value="Account 2" />
    <input id="Accounts_1__AccountId" name="Accounts[1].AccountId" type="hidden" value="95d75f76-16ef-4cf2-b1e7-5fad782002c5" />
    <input type="submit" value="Submit" />    
</form>

[HttpPost]
public ActionResult Index(Account accounts)
{
   ...
}
  • 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-20T04:38:58+00:00Added an answer on May 20, 2026 at 4:38 am

    You could try setting the prefix in your editor template:

    @model AppName.Models.Account
    @{
        ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
    }
    @using (Html.BeginForm("Index", "Home"))
    {
        @Html.TextBoxFor(x => x.AccountName)
        @Html.HiddenFor(x => x.AccountId)
        <input type="submit" value="Submit" />  
    }
    

    which if I am not mistaken should generate:

    <form action="/Home/Index" method="post">
        <input id="AccountName" name="AccountName" type="text" value="Account 1" />
        <input id="AccountId" name="AccountId" type="hidden" value="dddf5ca7-f8de-4192-b63a-3548f891e293" />
        <input type="submit" value="Submit" />    
    </form>
    

    Obviously you realize that by doing this you end up with invalid HTML (you will have multiple elements with the same id). A possible workaround would be to set the id manually:

    @Html.TextBoxFor(x => x.AccountName, new { id = "some unique value like a GUID" })
    @Html.HiddenFor(x => x.AccountId, new { id = "some unique value like a GUID" })
    

    Another possibility would be to write a custom model binder for the Account type which would simply ignore the prefix when binding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.