I suggest you ...

Support dynamic/anonymous types in views

Allow a view to manipulate anonymous models like new View(new {Name="John", Age=20}) and in cshtml file can access this properties like @Model.Age @Model.Name

65 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Thiago BurgoThiago Burgo shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    3 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Vasile BujacVasile Bujac commented  ·   ·  Flag as inappropriate

        This would be helpful when doing projections with Linq to Entity or Linq to NHibernate and passing anonymous objects directly to the view. The disadvantage is that you loose all the strong-typing, but you don't have to create many viewmodel classes. Sometimes these are numerous.
        Currently anonymous types are internal, and razor views are compiled as separate assemblies so dynamic doesn't work. Maybe a change to the DLR which would allow some of these anonymous types to be used with dynamic (annotated with an attribute maybe).

      Feedback and Knowledge Base