visual-studioasp.net-corerazor.net-7.0view-components

How to use View components in Visual Studio 17.5.0 in Linux


ASP .NET 7 MVC core application uses view commponents in Razor Views like in _Layout.chtml

<vc:producttree roott="ProductTreeRoot">
</vc:producttree>

After upgrading Visual Studio from 17.4.5 to 17.5.0 and deploying application to Linux view components are no more rendered. Markup in browser contains same <vc:producttree> element. If application in running from VS IDE in windows, markup contains proper html.

If Visual Studio is reverted back to 17.4.5 and older net runtime in forced in global.js using

 {   "sdk": {
     "version": "7.0.103",
     "rollForward": "disable"   }
 }

view components are rendered in Linux also. How to use views components in with .NET 7.0.200 and Visual Studio 17.5.0 ?

Related quiestion is in Why View Component is not rendered in production?


Solution

  • This is a known issue that occurs in .Net 7.0.200 and Visual Studio 17.5.0, If you don't want to use older net runtime, you can use:

    @await Component.InvokeAsync("xxxx")
    

    to render the view component.

    refer to github.