Peurr Peurr - 4 months ago 32
ASP.NET (C#) Question

ASP.NET Core Identity post request doesn't get called

I've ran into a problem with registering users using ASP.NET Identity in my ASP.NET Core project.

I've made things simpler by just changing the ViewData["Iets"] for now, just to check if it works, but no..

My controller:

public /*async Task<IActionResult>*/ IActionResult Register(RegisterViewModel model, string ReturnUrl = null)
ViewData["Iets"] = "Gelukt!";
return View();

//ViewData["ReturnUrl"] = ReturnUrl;

//if (ModelState.IsValid)
// var user = new ApplicationUser { Email = model.Email };
// var result = await _UserManager.CreateAsync(user, model.Password);

// if (result.Succeeded)
// {
// await _SignInManager.SignInAsync(user, false);
// _Logger.LogInformation(3, "User: {0}, has created a new account.", model.Email);

// return RedirectToLocal(ReturnUrl);
// }

// AddErrors(result);

//// If we got this far, something failed, redisplay form
//return View(model);

And my view:

@model Project_Dojo.Models.AccountViewModels.RegisterViewModel


<form asp-controller="Account" asp-action="Register" method="post">
<button type="submit">Button</button>

One thing I noticed is that my tags like
turn up in red color instead of purple as I have seen in other views.

So what happens when I press the button is that it just goes to
and returns a blank page instead of my layout page with the
on it.

I hope someone has a solution for this problem.


I forgot to add the HtmlHelpers in my _ViewImports.cshtml, that was the solution.