DamianEdwards / RazorSlices

Lightweight Razor-based templates for ASP.NET Core without MVC, Razor Pages, or Blazor.
MIT License
312 stars 13 forks source link

how to pass IServiceProvider to RenderPartialAsync #53

Closed ivanjx closed 3 months ago

ivanjx commented 3 months ago

i have a partial cshtml that needs to use @inject. im not sure on how to pass the service provider to that partial cshtml. on the parent cshtml, i do this in the c#:

var slice = RegistrationActivation.Create<RegistrationActivationModel>(
    new(language, name, link));
slice.ServiceProvider = _serviceProvider;

and this is what i do in the cshtml to generate the partial:

@(await RenderPartialAsync<RegistrationActivationButton, RegistrationActivationButtonModel>(
        new(Model.Language, Model.Link)))
DamianEdwards commented 3 months ago

It should just work. Are you seeing an error? Can you put together a minimal repro project and share it?

ivanjx commented 3 months ago

ah ok if it should just work. it was just a question. i will report it back if i encounter any issues.