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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:59:52+00:00 2026-05-20T21:59:52+00:00

I’m looking to see if there is a sample project, tutorial, contrib branch or

  • 0

I’m looking to see if there is a sample project, tutorial, contrib branch or anything like that that details implementing a custom ModelBinder for MVC3 to support objects inheriting from DynamicObject.

I have an domain object that has a dynamic number of properties as defined by the database, and these can change at run time. To make using the object easier I’ve made my class implementation inherit from DynamicObject and am passing the model to the view via the [dynamic] keyword.

All of the dynamic properties for the object are in a collection property on the object called “Attributes”. I’d like to create a series of editor templates to flesh out the model, ideally so all I have to do is make a call along the lines of Html.EditorForModel() and it will dynamically build the UI.

The problem is I’m not having much luck finding an implementation of a ModelBinder capable of inspecting a DynamicObject and scaffolding out the UI (I think that’s the right term for this?).

I found the IDictionary ModelBinder project done in one of the MVCConf videos done by Roberto Hernandez (@hernandezrobert) on MVC3 Extensability (source at http://mvcextensibility.codeplex.com/) but I haven’t had much luck adapting it to my purposes. I was wondering if anyone else has tried to create a model binder capable of doing what I’m describing? or could maybe point me in the right direction?

  • 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-20T21:59:52+00:00Added an answer on May 20, 2026 at 9:59 pm

    I was able to solve my situation by setting up a normal class to serve as the Model for my DanamicObject, and having my properties be stored like so

    IList<DynamicProperty> DynamicProperties { get; set; }
    

    I created a custom view for the DynamicObject, and in that view I called one of the helpers to display the DynamicProperties property. This lets MVC iterate through the collection and render each property. Next I have a view for the DynamicProperty that I use to render the property as needed. The key is you also have to render a hidden field containing the primary key of that specific attribute. The ModelBinder in MVC3 does a much better job here than it did in MVc2, so it will render the array index as part of the field’s name so that the primary key and value of each property get paired up correctly on the submit. You’ll likely want to create a ViewModel specifically for the submitted data, I had issues when I tried to use the same model class used in the details/edit views because I only rendered a subset of fields so they were missing when I bound to the same Model class on postback.

    You can handle the save however you would normally but there are a few considerations securitywise for this type of object. Because the number of attributes is dynamic, there is no way to ensure that the same number of fields are submitted as were originally rendered. The user could inject their own, or worse add in fields for a property you may have explicitly excluded. The AntiForgeryToken would prevent these sort of submissions from happened outside of your domain but with the ease and popularity of DOM manipulation provided by libraries like jQuery, cross site postbacks isn’t the only concerns and I don’t know if the AntiForgeryToken will account for this but I doubt it.

    This approach proved to be easier than trying to inherit from DynamicObject, implement GetDynamicMemberNames, and making a custom ModelBinder to use wrap around it.

    I did however create a custom ModelMetaData and Validation Provider to handle those aspects, since the properties are not strongly typed, so MVC didn’t have any annotations to use.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into

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.