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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:17:05+00:00 2026-05-20T20:17:05+00:00

Here is the situation. I have some ViewModels that contain nested complex model types.

  • 0

Here is the situation. I have some ViewModels that contain nested complex model types. Here is a snippet of one of the models (this is not a complete class):

/// <summary>
/// Defines the overall view when viewing contact details.
/// </summary>
public sealed class ContactDetailsViewModel : BaseViewModel
{
    public ContactDetailsViewModel() : base() { }
    public ContactDetailsViewModel(WebSession webSession) : base(webSession) { }
    public ContactDetailsViewModel(WebSession webSession, string returnUrl) : base(webSession, returnUrl) { }

    #region Contact
    /// <summary>
    /// The contact being viewed.
    /// </summary>
    public ContactModel Contact { get; set; }
    #endregion

And a snippet from the ContactModel class (not complete):

    #region Company
    [Required(AllowEmptyStrings = false)]
    [StringLength(128)]
    public string Company { get; set; }
    #endregion

My issue is that I need to be able to obtain the validation attributes from the nested model type, ContactModel, for client-side validation. I use the manual approach in most views because I don’t use the *For() helper methods. Here is what I do:

@Html.TextBox(
_titleField,
Model.Contact.Title,
new Dictionary<string,object>(Html.GetUnobtrusiveValidationAttributes("Company"))
{
    { "class", "CTextBox" },
    { "style", "width:100%;" }
})

This works like a champ and produces the expected validation attributes from the Model, ONLY, when the Model for the view is the Model that has the “validation” attributes applied. When the Model having the “validation” attributes is within a nested Model object, this does not work. I am struggling trying to figure out how to get the validation attributes for this scenario. The view is complicated, and I cannot decompose it any further into multiple views of models, so I need it working with a nested model.

I have tried numerous approaches, but won’t get into them yet in an attempt to get untainted answers. I will say I have tried using my binding prefix as well as going through some of the static “ModelMetadata” classes to drill into my nested model structure, but as of yet no luck. Any help is appreciated.

Let me know what else you need to maybe help.

I have also read a lot of Brad Wilson’s blog posts as well as other guys in his realm, but no luck so far.

  • 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-20T20:17:06+00:00Added an answer on May 20, 2026 at 8:17 pm

    You must to provide the complete name of the attribute:

    (Html.GetUnobtrusiveValidationAttributes("Contact.Company"))
    

    Where “Contact” is the name of the instance

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

Sidebar

Related Questions

Here's the situation: We have some generic graphics code that we use for one
Here is the situation. I have some javascript that looks like this: function onSubmit()
Here is my situation: I have an application that use a configuration file. The
Here is the situation. This small company I'm working with wants to have a
This is often situation, but here is latest example: Companies have various contact data
Okay here's the situation. Net 4 WPF NO Silverlight. I have several Views that
so, here is the situation here. I have 2 asp.net websites + some winform
Here is the situation: I have inherited two separate machines, one used for development
Here is the situation: I have a huge data set that I need quick
Here’s the situation: We have a 3rd party application that intermittently displays an error

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.