Access database from usercontrol

Hi,
Is there a way to access the database from within the user control?

I don’t think there is anything stopping you from doing that. You can request any dependencies from DI by adding them as a constructor parameter.

However, I’d advice against it and suggest placing the data fetching logic into the ViewModel of the control, if it a markup control. Nested view models can also inherit DotvvmViewModelBase and override the Init, Load, PreRender methods.

1 Like