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
    0

    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
    1

    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:

    https://www.davepaquette.com/archive/2016/01/02/goodbye-child-actions-hello-view-components.aspx

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

    https://github.com/umbraco/Umbraco-CMS/pull/9762#issuecomment-774797292

    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: https://github.com/umbraco/Umbraco-CMS/pull/9915 is related to Forms and mentions testing with a ViewComponent...

    And this is kinda an example ViewComponent in the core:

    https://github.com/umbraco/Umbraco-CMS/blob/netcore/dev/src/Umbraco.Web.Common/Macros/PartialViewMacroViewComponent.cs

    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!

    regards

    marc

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

    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:

Draft