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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:17:26+00:00 2026-05-26T17:17:26+00:00

What I have is a model which has one of it’s attributes dynamic. This

  • 0

What I have is a model which has one of it’s attributes dynamic. This dynamic attribute holds one of about 50 different objects. This model is send to a view that dynamic creates the page based on which object is used. This is working perfectly … the issue is the postback. When the model posts back the modelbinder is not able to bind the dynamic attribute. I was expecting this and thought I would be able to handle it but nothing that I tried works appart from making an action for EACH different objects.

Model

public class VM_List
{
    public Config.CIType CIType { get; set; }
    public dynamic SearchData { get; set; }
   //Lots of static fields
}

This works

public ActionResult List_Person(VM_List Model, VM_Person_List SearchData)
{
Model.SearchData = SearchData;
//Stuff
}

public ActionResult List_Car(VM_List Model, VM_Car_List SearchData)
{
Model.SearchData = SearchData;
//Stuff
}

But what I want is a single action

public ActionResult List(VM_List Model)
{
    //Stuff
}

I have tried things like

public ActionResult List(VM_List Model)
{

        switch (Model.CIType)
        {
            case Config.CIType.Person:
                UpdateModel((VM_Person_List)Model.SearchData);
                break;
            default:
                SearchData = null;
                break;
        }

    //Stuff
}

and a Custom modelbinder

CIType CIType = (CIType)bindingContext.ValueProvider.GetValue("CIType").ConvertTo(typeof(CIType));

switch (CIType)
{
            case Config.CIType.Person:
                SearchData = (VM_Person_List)bindingContext.ValueProvider.GetValue("SearchData").ConvertTo(typeof(VM_Person_List));
                break;
            default:
                SearchData = null;
                break;
        }

but I can’t get either to work. Any ideas?

  • 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-26T17:17:27+00:00Added an answer on May 26, 2026 at 5:17 pm

    After trying many different things I finally found a way that works.

    Action:

    public ActionResult List(VM_List Model)
    {
    
    //If the defaultmodelbinder fails SearchData will be an object
    if(Model.SearchData.GetType() == typeof(object))
    {
    
    //Get SearchData as a Dictionary
    Dictionary<string, string> DSearchData = Request.QueryString.AllKeys.Where(k => k.StartsWith("SearchData.")).ToDictionary(k => k.Substring(11), k => Request.QueryString[k]);
    
    switch (Model.CIType)
    {
                    case Config.CIType.Person:
                        Model.SearchData = new VM_Person_List(DSearchData);
                        break;
                    case Config.CIType.Car:
                        Model.SearchData = new VM_Car_List(DSearchData);
                        break;
    }
    
    //Rest of action
    //..
            }
    

    and for each object make a constructor that accepts a dictionary

    public VM_Car_List(Dictionary<string, string> DSearchData)
    {
        this.Make = Convert.ToInt32(DSearchData["Make"]);
        this.Model = Convert.ToInt32(DSearchData["Model"]);
        this.Year = Convert.ToInt32(DSearchData["Year"]);
        // ETC
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User model in which the user has one attribute named division
I have a model which has a collection of users. I'm looping through this
I have a User model, which has a workplace attribute. The Workplace is not
i have a user model which has one image. how can i disable the
I have a Content model which has one or many Audio files which need
I have a django application which has one main table/model which references various 'lookup'
Suppose I have a model Person which has a one to many relationship with
I have a model which has one main table with 22 fields and 5
I have a data model which has two entities in a relationship of one
I have model Foo which has field bar. The bar field should be unique,

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.