ASP.NET Web API controller can't handle dynamic objects?http://forums.asp.net/t/1773523.aspx/1?ASP+NET+Web+API+controller+can+t+handle+dynamic+objects+Tue, 13 Mar 2012 21:23:38 -040017735234849743http://forums.asp.net/p/1773523/4849743.aspx/1?ASP+NET+Web+API+controller+can+t+handle+dynamic+objects+ASP.NET Web API controller can't handle dynamic objects? <p>In my code I have a base class Foo and all my objects inherits from the Foo object. So let's say I have a class like this</p> <pre><pre class="prettyprint">public class Bar : Foo { public string Heading { get;set; } }</pre></pre> <p>I have tried to use the ApiControllers put method with dynamic but I get this error<a href="http://paste2.org/p/1914054" rel="nofollow">http://paste2.org/p/1914054</a></p> <p>This is the code I'm using in the ApiController</p> <pre><pre class="prettyprint">public void Put(string id, dynamic model) { //do stuff } </pre></pre> <p>If I use a normal controller I can use dynamic to post data. How can I make it work with dynamic objects?</p></pre> 2012-02-24T16:27:54-05:004850068http://forums.asp.net/p/1773523/4850068.aspx/1?Re+ASP+NET+Web+API+controller+can+t+handle+dynamic+objects+Re: ASP.NET Web API controller can't handle dynamic objects? <p>Your input pararameters cannot be dynamic in Web API (nor can they in MVC, I'm not sure why you think they can).</p> 2012-02-24T21:28:31-05:004850375http://forums.asp.net/p/1773523/4850375.aspx/1?Re+ASP+NET+Web+API+controller+can+t+handle+dynamic+objects+Re: ASP.NET Web API controller can't handle dynamic objects? <p>I'm not thinking it works, I know it works in MVC 3. <a href="https://github.com/kloojed/BrickPile/blob/master/src/BrickPile/BrickPile.Sample/Areas/BrickPile.UI/Controllers/ContentController.cs#L93"> This works just perfect here</a> so my question is still why it doesn't work with the API controller?</p> 2012-02-25T07:00:33-05:004878283http://forums.asp.net/p/1773523/4878283.aspx/1?Re+ASP+NET+Web+API+controller+can+t+handle+dynamic+objects+Re: ASP.NET Web API controller can't handle dynamic objects? <p>If you are fine with only using the built-in JSON media type formatter (no XML, Json.NET etc) then you can take a parameter of type JsonValue and call AsDynamic on it to get a dynamic variable representing the content. If you don't want to lock yourself into using only System.Json, you could take a parameter of type IKeyValueModel. It's not as easy to work with but it gives you essentially the same functionality. It probably wouldn't be too difficult to map an IKeyValueModel to a dynamic.</p> 2012-03-13T19:15:02-04:004878444http://forums.asp.net/p/1773523/4878444.aspx/1?Re+ASP+NET+Web+API+controller+can+t+handle+dynamic+objects+Re: ASP.NET Web API controller can't handle dynamic objects? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>kloojed</h4> <a href="https://github.com/kloojed/BrickPile/blob/master/src/BrickPile/BrickPile.Sample/Areas/BrickPile.UI/Controllers/ContentController.cs#L93">This works just perfect here</a> so my question is still why it doesn't work with the API controller?</blockquote> <p></p> <p>Your sample code does not actually use the editorModel parameter. The value is probably just null.</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>cstraw</h4> If you don't want to lock yourself into using only System.Json, you could take a parameter of type IKeyValueModel.</blockquote> <p></p> <p>Don't use IKeyValueModel. We are going to remove that interface.</p> <p>&nbsp;</p> 2012-03-13T21:23:38-04:00