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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:18:05+00:00 2026-06-08T06:18:05+00:00

I have two view models, one aggregating a collection of the other: class Parent

  • 0

I have two view models, one aggregating a collection of the other:

class Parent 
{
   public string Key { get; set; }
   public IList<Child> Children { get; set; }
}

class Child
{
   public string Key { get; set; }

   [Required, Remote("VerifyNameUnique", "Parent", AdditionalFields = "Key", ErrorMessage = "The name must be unique.")]
   public string Name { get; set; }
}

I have a controller action

public ActionResult VerifyNameUnique(string key, string name)
{
    var result = // ... verify uniqueness
    return Json(result, JsonRequestBehavior.AllowGet);
}

And a view:

@model Parent
@Html.HiddenFor(m => m.Key)
@for(var i=0; i<Model.Children; i++)
{
   @Html.HiddenFor (m => m.Children[i].Key)
   @Html.LabelFor(m => m.Children[i].Name)
   @Html.EditorFor (m => m.Children[i].Name)
}

When my Parent/Child editor template calls the action to validate any of the Name fields, it sends a querystring ?Children[0].Key=abc&Children[0].Name=Fred, where 0 is the index i of the child just edited.

That doesn’t bind to the parameters of VerifyNameUnique because of the prefix. I have tried using BindAttribute with a prefix set, but the prefix varies by the value of i.

Writing a custom model binder is an option but seems like overkill right now for this simple scenario. Is there anything nicer I can do?

  • 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-08T06:18:06+00:00Added an answer on June 8, 2026 at 6:18 am

    This simply is not supported. So you will have to either write a custom model binder or a custom Remote validation attribute. This being said, what you are trying to achieve is probably not a very good idea because if the user clicks on the submit button an AJAX request will be sent for every field in the collection which is not very efficient. I would probably go with a custom remote validation field directly on the collection property on the parent in order to validate everything with a single roundtrip to the server.

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

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
I relised I have lots of models view models with those two properties public
I have two models in cakePHP, one is Parts and the other is Orders
I have two views, one represents a view of clients and the other is
I have my view models : public class POReceiptViewModel { public virtual int PONumber
I have two models, one is Group, the other Item. A group has many
Want to use two models in one view. I have two controllers one for
suppose I have a model and a view ,ths view have two method:one is
I have two models that are related to each other. For a contrived example,
I have two models, Product and Product_Methodology. In my product edit view I have

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.