How to use View components in Visual Studio 17.5.0 in Linux
Asked Answered
U

1

0

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?

Undistinguished answered 22/2, 2023 at 22:45 Comment(0)
H
1

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.

Haag answered 23/2, 2023 at 2:44 Comment(3)
When using a ModelExpression parameter this method cannot be used as they only work with the tag helper. ´public async Task<IViewComponentResult> InvokeAsync(ModelExpression model, string pageCode, bool debug = false)´ How to use it in ´7.0.200´ ?Undistinguished
Sorry, Because ModelExpression parameter can only work with the tag helper, So I am afraid you can only use tag helper with older .net runtime to achieve it until this issue has been fixed.Haag
Oh great, two hours wasted wondering what the hell I did wrong. Nice work Microsoft.Cahn

© 2022 - 2024 — McMap. All rights reserved.