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.
尝试将[HttpPost]
作为操作的属性。
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.
Is your view called Register.cshtml
? If it isn't, if it's something like Register.html
then it wont behave as an MVC view. Maybe try correcting the file extension if it isn't cshtml
.
我忘了在我的_ViewImports.cshtml中添加HtmlHelpers,这就是解决方案。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.