Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net core View components model binding

I'm looking for a way to invoke Model binder inside View component. I prefer to use build-in functionality from asp.net core, but this is only available inside controllers, not View Components itself. Any way to resolve that problem?

like image 742
Thomas K Avatar asked Mar 12 '23 14:03

Thomas K


1 Answers

According to View Components documentation:

View Components don’t use model binding, and only depend on the data you provide when calling into it.


However, you could pass model as an object/parameter into your ViewComponent:

@await Component.InvokeAsync("PriorityList", MyModel)

or

@await Component.InvokeAsync("PriorityList", new { maxPriority = 2, isDone = false })


What do you want to achieve?

like image 155
Lukasz Mk Avatar answered Mar 24 '23 06:03

Lukasz Mk