Steve Fenton

Html.RenderAction equivalent in .NET Core MVC

If you were a fan of ASP.NET MVC Widgets using Html.RenderAction, you might be a bit stunned that RenderAction is nowhere to be found in .NET Core. Don’t worry, though, because there is a Html.RenderAction equivalent in .NET Core MVC and it’s called View Components.

View component class

The view component class is quite a lot like a controller. It inherits from the ViewComponent class and should be named [Something]ViewComponent as this is a convention. You grab a model and send it to a view in a very familiar way.

The View Component class always has an Invoke method.

    public class NavigationViewComponent
        : ViewComponent

        public IViewComponentResult Invoke()
            SomeModel model = GetSomeModel();

            return View(model);

Default view

The view needs to be placed in a special location. View Components views are placed in a folder structure according to the View Component name.


Because my View Component class is called NavigationViewComponent, it goes in:


The view itself is just like any Razor view… so you’ll already know all about that!

Rendering the action, er… Invoking the View Component

All you need to do to call out to the View Component is invoke it.

@await Component.InvokeAsync("Navigation")

If you need to pass arguments, that’s easy too:

@await Component.InvokeAsync("Navigation", new { page = 3 })

This will call out to the view component, which will go and get the data it needs, and render the content that will appear where you first invoked it.


View Components are a neat way to implement Widgets in your .NET Core MVC application.

Written by Steve Fenton on