Peurr Peurr - 13 days ago 6
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

@ViewData["Iets"]

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


One thing I noticed is that my tags like
asp-controller
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
localhost/Account/Register
and returns a blank page instead of my layout page with the
ViewData
on it.

I hope someone has a solution for this problem.

Answer

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

Comments