public class Model1 { [Required(ErrorMessage="Username must not be blank")] public string Username { get; set; } [Required(ErrorMessage="Password should match")] public string Password { get; set; } }
public class HomeController : Controller { [HttpGet] public ActionResult Index() { return View(); } [HttpPost] public ViewResult Index(Model1 model1) { if (ModelState.IsValid) { if (model1.Username == "adm" && model1.Password == "adm") { return View("FWMenu", model1); } else { return View(); } } return View(); }
<h1> Log-in</h1> <br /> @Html.ValidationSummary() @using (@Html.BeginForm()) { <p>@Html.TextBoxFor(x => x.Username)</p> <p>@Html.TextBoxFor(x => x.Password)</p> <br /> <p> <input type="submit" value="Login" /></p> } </div>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)