[英]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. 我在ASP.NET Core项目中使用ASP.NET Identity注册用户时遇到了问题。
I've made things simpler by just changing the ViewData["Iets"] for now, just to check if it works, but no.. 我现在通过仅更改ViewData [“ Iets”]来简化事情,只是检查它是否有效,但是没有。
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. 我注意到的一件事是,像
asp-controller
这样的标签变成了红色,而不是我在其他视图中看到的紫色。
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. 因此,当我按下按钮时会发生什么,那就是它会转到
localhost/Account/Register
并返回一个空白页面,而不是我的带有ViewData
布局页面。
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.
我注意到的一件事是,像asp-controller这样的标签变成了红色,而不是我在其他视图中看到的紫色。
Is your view called Register.cshtml
? 您的视图名为
Register.cshtml
吗? If it isn't, if it's something like Register.html
then it wont behave as an MVC view. 如果不是,则类似于
Register.html
那么它将不会充当MVC视图。 Maybe try correcting the file extension if it isn't cshtml
. 如果不是
cshtml
尝试更正文件扩展名。
我忘了在我的_ViewImports.cshtml中添加HtmlHelpers,这就是解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.