Skip to content

Instantly share code, notes, and snippets.

@hugoware
Created July 27, 2011 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugoware/1110448 to your computer and use it in GitHub Desktop.
Save hugoware/1110448 to your computer and use it in GitHub Desktop.
Using Json.Encode/Decode To Convert Anonymous Types
//using an anonymous type directly (even being passed in as a Dynamic)
//will result in an exception message. Using this converts the Anonymous
//type to a dynamic that can be used as expected
//this doesn't include any validation of properties but it can be done
@helper something_that_renders_lists(params dynamic[] links) {
links = Json.Decode(Json.Encode(links));
<ul>
@foreach(var link in links) {
<li><a href="@link.url" >@link.text</a></li>
}
</ul>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment