In Razor Pages, how do I access @injected variables such as a UserManager in the code-behind?

I have this in my Delete.cshtml:

@inject UserManager<IdentityUser> UserManager 

And in Delete.cshtml.cs, I’m trying to access this UserManager (to make sure you can only delete items created by you) but I can’t; I get a compile error saying it’s undefined. Is there any way to do this? The UserManager<T> constructor takes a lot of parameters which I wouldn’t know how to fill, so that’s probably not the right way to do it…

submitted by /u/ekolis
[link] [comments]

Leave a Reply