Created
July 27, 2011 21:45
-
-
Save hugoware/1110448 to your computer and use it in GitHub Desktop.
Using Json.Encode/Decode To Convert Anonymous Types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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