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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:30:03+00:00 2026-06-08T03:30:03+00:00

I have a ViewModel called AssetSearchModel with a property of type: List. When I

  • 0

I have a ViewModel called AssetSearchModel with a property of type: List.

When I post from the ViewModel, all the properties of my List get binded back to the model successfully, except for this one: public DomainsDto DomainControl { get; set; } which is defined at the bottom.

That domaincontrol has a couple of properties and then its own nested list… none of its properties get set, they are all null

public class AssetSearchModel
{
    public List<SearchControlModel> SearchControls { get; set; }

    public AssetSearchModel()
    {
    }

}

public class SearchControlModel
{

    /// <summary>
    /// Asset identifier.
    /// </summary>
    [DisplayName("AssetId ID")]
    public int SearchOptionID { get; set; } // this gets bound ok

    [DisplayName("Asset Customer ID")]
    public int AssetCustomerID { get; set; } // this gets bound ok

    [DisplayName("Portal ID")]
    public int PortalID { get; set; } // this gets bound ok

    [DisplayName("Calling Page")]
    public string CallingPage { get; set; } // this gets bound ok

    [DisplayName("Display Control")]
    public string DisplayControl { get; set; } // this gets bound ok

    [DisplayName("Display Text")]
    public string DisplayText { get; set; } // this gets bound ok

    public string ControlValue { get; set; } // this gets bound ok

    [DisplayName("Search Table")]
    public string SearchTable { get; set; } // this gets bound ok

    [DisplayName("Search Column")]
    public string SearchColumn { get; set; } // this gets bound ok

    [DisplayName("Source Table")]
    public string SourceTable { get; set; } // this gets bound ok

    [DisplayName("Source Display Column")]
    public string SourceDisplayColumn { get; set; } // this gets bound ok

    [DisplayName("Source Value Column")]
    public string SourceValueColumn { get; set; } // this gets bound ok

    [DisplayName("SourceCustomFilter")]
    public string SourceCustomFilter { get; set; } // this gets bound ok

    [DisplayName("SortOrder")]
    public int SortOrder { get; set; } // this gets bound ok

    [DisplayName("DomainControl")]
    public DomainsDto DomainControl { get; set; } // THIS DOES NOT BIND

    public SearchControlModel()
    {



    }

}

public class DomainsDto
{
    public int DomainMasterId;      // this does not bind
    public string DisplayName;     // this does not bind
    public List<DomainDto> Domains;  // this does not bind
    public DomainsDto()
    {

    }

}

[DataContract(Name = "Domain", Namespace = "http://www.comcom.com/")]

public class DomainDto
{
    [DataMember]
    public int DomainID { get; set; }   // this does not bind

    [DataMember]
    public string DomainName { get; set; }  // this does not bind

    [DataMember]
    public bool Checked { get; set; }   // this does not bind


    public DomainDto()
    {

    }
}

and my view:

         @for (int y = 0; y < Model.SearchControls.Count; y++)
     {

        @Html.Label("Search option: " + Model.SearchControls[y].DisplayText)
        <br />
        @Html.HiddenFor(x => x.SearchControls[y].DisplayText)
        @Html.HiddenFor(x => x.SearchControls[y].CallingPage)
        @Html.HiddenFor(x => x.SearchControls[y].DisplayControl)
        @Html.HiddenFor(x => x.SearchControls[y].SourceCustomFilter)
        @Html.HiddenFor(x => x.SearchControls[y].SearchTable)
        @Html.HiddenFor(x => x.SearchControls[y].SearchColumn)
        @Html.HiddenFor(x => x.SearchControls[y].SourceValueColumn)


         if (Model.SearchControls[y].DomainControl != null)
         {

             @Html.HiddenFor(x => x.SearchControls[y].DomainControl.DisplayName) 

             @Html.HiddenFor(x => x.SearchControls[y].DomainControl.DomainMasterId)

             if (Model.SearchControls[y].DomainControl.Domains != null)
             {
                 for (int z = 0; z < Model.SearchControls[y].DomainControl.Domains.Count; z++)
                 {

                    @Html.HiddenFor(x => x.SearchControls[y].DomainControl.Domains[z].DomainID)
                    @Html.HiddenFor(x => x.SearchControls[y].DomainControl.Domains[z].DomainName)
                    @Html.HiddenFor(x => x.SearchControls[y].DomainControl.Domains[z].Checked)


                    <br />
                 }
             }
         }

         <br />
         <br />
         <hr width=100px />


     }

the html (sorry for the single line, it wouldn’t let me paste it in differently)

<label for="Search_option:_Product_Lines">Search option: Product Lines</label> <input id="SearchControls_1__DisplayText" name="SearchControls[1].DisplayText" type="hidden" value="Product Lines" /> <input id="SearchControls_1__CallingPage" name="SearchControls[1].CallingPage" type="hidden" value="AssetSearch" /> <input id="SearchControls_1__DisplayControl" name="SearchControls[1].DisplayControl" type="hidden" value="M" /> <input id="SearchControls_1__SourceCustomFilter" name="SearchControls[1].SourceCustomFilter" type="hidden" value="26" /> <input id="SearchControls_1__SearchTable" name="SearchControls[1].SearchTable" type="hidden" value="AssetDomainValue" /> <input id="SearchControls_1__SearchColumn" name="SearchControls[1].SearchColumn" type="hidden" value="Brand" /> <input id="SearchControls_1__SourceValueColumn" name="SearchControls[1].SourceValueColumn" type="hidden" value="DomainCodeValueID" />   <input id="SearchControls_1__DomainControl_DisplayName" name="SearchControls[1].DomainControl.DisplayName" type="hidden" value="Product Line" /> <input id="SearchControls_1__DomainControl_DomainMasterId" name="SearchControls[1].DomainControl.DomainMasterId" type="hidden" value="26" />  <input id="SearchControls_1__DomainControl_Domains_0__DomainID" name="SearchControls[1].DomainControl.Domains[0].DomainID" type="hidden" value="43680" /> <input id="SearchControls_1__DomainControl_Domains_0__DomainName" name="SearchControls[1].DomainControl.Domains[0].DomainName" type="hidden" value="YORK" /> <input id="SearchControls_1__DomainControl_Domains_0__Checked" name="SearchControls[1].DomainControl.Domains[0].Checked" type="hidden" value="False" />                        <input id="SearchControls_1__DomainControl_Domains_1__DomainID" name="SearchControls[1].DomainControl.Domains[1].DomainID" type="hidden" value="43683" /> <input id="SearchControls_1__DomainControl_Domains_1__DomainName" name="SearchControls[1].DomainControl.Domains[1].DomainName" type="hidden" value="Johnson Controls" /> <input id="SearchControls_1__DomainControl_Domains_1__Checked" name="SearchControls[1].DomainControl.Domains[1].Checked" type="hidden" value="False" />                        <br />
  • 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-08T03:30:08+00:00Added an answer on June 8, 2026 at 3:30 am

    Ah no, the model binder works only with properties only, not fields.

    So replace:

    public class DomainsDto
    {
        public int DomainMasterId;       // this does not bind
        public string DisplayName;       // this does not bind
        public List<DomainDto> Domains;  // this does not bind
        public DomainsDto()
        {
    
        }
    }
    

    with:

    public class DomainsDto
    {
        public int DomainMasterId { get; set; }       // this does bind
        public string DisplayName  { get; set; }      // this does bind
        public List<DomainDto> Domains { get; set; }  // this does bind
        public DomainsDto()
        {
    
        }
    }
    

    But really, what’s the whole point of stuffing a gazzilion of hidden fields in a form? You already have this stuff in your db or something. So simply put a hidden field containing an id that will allow you to go and fetch the data wherever this data resides. I’ve always wondered people why are people so desperately trying to reinvent the ViewState for MVC. It’s just not the way this pattern is meant to be used. You are no longer doing classic WebForms.

    Here’s a rule that should drive you when designing an ASP.NET MVC view:

    • whatever fields the user is supposed to modify use corresponding input fields (textboxes, radios, ddls and stuff)
    • whatever fields the user is not supposed to modify, it shouldn’t appear in the form. You should have at maximum one hidden field per form containing at maximum an unique identifier allowing you to retrieve the information you need

    Conclusion: use view models.

    So the real solution to your problem is to replace:

    [DisplayName("DomainControl")]
    public DomainsDto DomainControl { get; set; } // THIS DOES NOT BIND
    

    with:

    public int DomainControlId { get; set; }
    

    and using a single hidden field for this id in the view. That’s it.

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

Sidebar

Related Questions

ViewModel I have a property of type Member called KeyMember . The 'Member' type
I have a button whose content is binded with ViewModel's property called Test. <Button
I have a ViewModel called EntityRating, one of whose properties is AverageRating. When I
In my SilverLight application, I have a property in my ViewModel called 'vmProperty' and
I have a ViewModel called MainWindowViewModel. In this I have a property that shows
I have a viewmodel called ArticleAdmin that includes a list of checkboxes: public class
Here's the situation, I have a list of about 20 properties (called Attributes) that
I have a view model public class ViewModel { public string Text { get;
I have a textbox that is bound to a property on my ViewModel called
I have a ViewModel called CompanyListViewModel . It represents a list of companies in

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.