-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ViewComponents as TagHelpers with optional parameters #5541
Comments
In our initial prototypes we supported this but removed support due to holes in our implementation. @ajaybhargavb we can support this when we move ViewComponent TagHelper attribute checks to be at runtime. |
@NTaylorMullen So was this given up on? |
@shanselman We've lately been more aggressive in backlogging/closing items. Given that it's not closed we haven't given up on it yet. It just means it hasn't yet fit into any of the currently planned milestones. Lots of pieces moving currently! 😄 |
I've spent like 3 hours trying to figure out why on earth my ViewComponent was not working until I created a new project and found out the problem was the optional parameter. The documentation found here SHOULD be updated to reflect that https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components |
Duplicate/tracked in different repo: https://github.com/aspnet/Razor/issues/1266 |
The new TagHelper syntax for ViewComponents looks great, but it seems that it'll only match the attributes you specify exactly to those on your
Invoke()
orInvokeAsync()
method signature. Is that correct? It makes any kind of optional parameters impossible as far as I can see.So with an example ViewComponent:
Either of the following work correctly:
However either of the following are output directly to the HTML unprocessed:
It's not possible to overload the
Invoke()
methods and the default values for parameters will never be used. In a more complex example than above you can see that adding a new optional parameter to a ViewComponent will cause it to silently fail anywhere that the attributes and signatures do not match, writing server side code to the browser.The text was updated successfully, but these errors were encountered: