admin管理员组文章数量:1221307
In my ASP.NET Core MVC website, I have a registration form. When I fill all the fields and I press the "Create Account" button, I stay in the same page, and the URL changes from
https://localhost:44395/CriarConta/Register?area=CriarConta
to
https://localhost:44395/CriarConta/Register
My register form (called CriarConta
) has the method=post
.
My problem is that the form isn't saving the user's information in the database, and I would like to solve this problem.
In case you need, here's my CriarContaController
:
using Microsoft.AspNetCore.Mvc;
using SportMotos.Models;
namespace SportMotos.Controllers
{
public class CriarContaController : Controller
{
private readonly AppDbContext _context;
public CriarContaController(AppDbContext context)
{
_context = context;
}
// Shows the form (GET)
[HttpGet]
public IActionResult Register()
{
return View();
}
// Processess the form(POST)
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Register(Cliente model)
{
if (ModelState.IsValid)
{
// Adds a new user to the DB
model.DataCriacao = DateTime.Now;
_context.Clientes.Add(model);
await _context.SaveChangesAsync();
return RedirectToAction("Index", "Home");
}
return View(model);
}
}
}
本文标签: cASPNET Core MVC form not inserting data into databaseStack Overflow
版权声明:本文标题:c# - ASP.NET Core MVC form not inserting data into database - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739294477a2156842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论