Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mitch 42 posts 157 karma points
    Sep 14, 2017 @ 09:43
    Mitch
    0

    Route Hijacking and custom ViewModels

    I'm using 7.6.4 and I'm sure a feature I've used in earlier versions is now missing - the ability to use custom ViewModels that don't inherit from RenderModel in a view.

    I'm sure this has worked previously:

    ViewModel:

       public class PersonViewModel
       {
           public string FirstName {get; set;}
           public string LastName {get; set;}
       }
    

    ... hijack the route with a controller then render the View:

    @model PersonViewModel
    
    <div>@Model.FirstName @Model.LastName</div>
    

    This no longer seems to work anymore and I'm being forced to make my ViewModels inherit from RenderModel, injecting the PublishedContent object and culture just to instantiate them.

    Pretty sure I created a whole site using the above method but I no longer have the code to prove it.

    Am I doing something wrong or has this feature been removed?

Please Sign in or register to post replies

Write your reply to:

Draft