Copied to clipboard

Flag this post as spam?

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

  • Søren Kottal 538 posts 3565 karma points MVP 2x c-trib
    7 days ago
    Søren Kottal

    Render action from Surface Controller

    Seems like Html.Action and Html.RenderAction is replaced by something new called ViewComponents in .net 5.

    Does this mean we can't render actions from SurfaceControllers in our views with @Html.RenderAction("MyActionMethod", "MySurfaceController") anymore?

  • Marc Goodson 1482 posts 9934 karma points MVP 5x c-trib
    7 days ago
    Marc Goodson

    Hi Soren

    I don't know but your question got me snooping, and I thought I'd write down some things I found:

    so yes ChildActions are not a thing it seems in .net core:

    With regard to SurfaceControllers, I found this commit where Shannon has refactored all things SurfaceControllers for .net core, and this comment here:

    Yep these routes are really just for postbacks. For the most part SurfaceControllers are only for: post backs and 'child actions' (but those don't exist anymore). I created a separate task to test view components with forms to ensure they work.

    So this further PR: is related to Forms and mentions testing with a ViewComponent...

    And this is kinda an example ViewComponent in the core:

    So it seems like ViewComponents could be pretty cool within the context of Umbraco, you can inject services into their constructor using di (think umbraco services) and pass in additonal parameters (like macros) and they aren't part of the request eg like child actions - but it seems using either invoke or invokeasync, you can conjure up a model in C# and send it through to a View...

    ... which if I've understood, will be pretty cool.

    With the constructor injection, there isn't any need for any special UmbracoViewComponent base class or anything to access the cache...

    ... all interesting stuff.

    Not sure that answers the question though!



  • Søren Kottal 538 posts 3565 karma points MVP 2x c-trib
    7 days ago
    Søren Kottal

    Thanks Marc, I did browse around looking for ViewComponents, but obviously you were better than me :)

    That PartialViewMacro thing seems to be controllerbased in v8, so looks like v9+ is going to be ViewComponents. That should be good enough for me :)

Please Sign in or register to post replies

Write your reply to: