I try to create a form with Html.BeginForm()
helper. But it throws exceptions:
XmlException: Root element is missing.
System.Xml.XmlTextReaderImpl.Throw(Exception e)
CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information.
Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(byte[] plaintext)
This is standard ASP.Net MVC Application. I changed the controller code, add view-model and view classes. That's all.
Controller:
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Login(UserVM userVM)
{
return Json(userVM);
}
}
ViewModel:
public class UserVM
{
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
public string Password { get; set; }
}
View:
@using WebApplication1.ViewModels
@model UserVM
@using (Html.BeginForm("Login", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.TextBoxFor(m=>m.Email)
@Html.PasswordFor(m=>m.Password)
}
This is what I get:
What I am doing wrong?