I am trying to move the register page that was scaffolded by ASP.net core to a controller so I can have a better control on the way I open it and for organisation reasons. Where the view was previously in
Areas
- Identity -- Pages --- Account
now, I want it to be at
Views -Account
And I want to open this view using an AccountController.
I tried opening it; starting the model; calling some methods, just like this:
[HttpGet]
public async Task<IActionResult> RegisterAsync()
{
var model = new RegisterModel(_userManager, _userStore, _signInManager, _logger, _emailSender);
model.OnGetAsync("Home/Index").Wait() ;
return View("Register", model);
}
Everytime I call the action on the controller, I get an exception in the View itself that the model is null.
What should I do?
When you try with MVC ,the services shouldn't be required for your viewmodel ,also, you have to move the codes inside your Razor Page Handlers into ccontroller,don't call the handler directly(
model.OnGetAsync("Home/Index")),a minial example here:Models:
View:
Controller:
Result: