ASP.NET MVC UpdateModel doesn't update inherited public properties??
        Posted  
        
            by mrjoltcola
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by mrjoltcola
        
        
        
        Published on 2010-04-15T18:18:05Z
        Indexed on 
            2010/04/15
            20:33 UTC
        
        
        Read the original article
        Hit count: 397
        
asp.net-mvc
I refactored some common properties into a base class and immediately my model updates started failing. UpdateModel() and TryUpdateModel() do not seem to update inherited public properties.
I cannot find detailed info on MSDN nor Google as to the rules or semantics of these methods. The docs are terse (http://msdn.microsoft.com/en-us/library/dd470933.aspx), simply stating:
Updates the specified model instance using values from the controller's current value provider.
Well that leads us to believe it is as simple as that. It makes no mention of limitations with inheritance. My assumption is the methods are reflecting on the top class only, ignoring base properties, but this seems to be an ugly shortcoming, if so.
SOLVED: Eep, this turned out to have nothing to do with inheritance. My base class was implemented with public fields, not properties. Switching them to formal properties (adding {get; set; }) was all I needed. This has bitten me before, I keep wanting to use simple, public fields.
© Stack Overflow or respective owner