So far I have been able to translate everything in an ASP.Net Core 2.1 Web Application.
It has proven a little challenge, since the scaffolded Account Pages needed a
You can use ViewModel
and than you can just use DataAnnotations
here is how Controller
, ViewModel
and View
looks in that case (translation is Croatian).
[HttpGet]
public IActionResult Login()
{
return View();
}
[HttpPost]
public async Task Login(LoginViewModel model)
{
if (ModelState.IsValid)
{
var result = await signInManager.PasswordSignInAsync(
model.Email, model.Password, model.RememberMe, false);
if (result.Succeeded)
{
return RedirectToAction("index", "home");
}
ModelState.AddModelError(string.Empty, "Neuspješni pokušaj");
}
return View(model);
}
Under ErrorMessage
put your error message
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace MyApplication.ViewModels
{
public class LoginViewModel
{
[Required(ErrorMessage = "Email je obavezan")]
[EmailAddress]
public string Email { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Lozinka")]
[Required(ErrorMessage = "Lozinka je obavezna")]
public string Password { get; set; }
[Display(Name = "Zapamti me")]
public bool RememberMe { get; set; }
}
}
@model LoginViewModel
@{
ViewBag.Title = "Prijava";
}
Prijava