So I have a view containing a HTML login form and I need to get the values from the form to a controller via post. Right now I'm trying to display the username of the user through the Content method when the form is submitted, once I know I have the username in the controller I can do the rest. The problem I have is that when I submit the form the username is not displayed, I've outputted to the console to check if the controller action is being called and it isn't.
Any help is greatly appreciated cheers!
View
@{
@model AdminPanel.Models.cUser
Layout = null;
ViewBag.Title = "Login";
}
<head>
<link href="~/Content/Login.css" rel="stylesheet" type="text/css" />
<link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- Div containing the log in box parent -->
<div class="log-in-box-parent">
<h2>LOG IN</h2>
<div class="log-in-form">
<form asp-action="Login" asp-controller="Login">
<input asp-for="Username" type="text" id="Username" placeholder="Username" /> <br />
<input aso-for="Password" type="password" id="Password" placeholder="Password" /> <br />
<input type="submit" id="login" value="Log in"/>
</form>
</div>
</div>
</body>
Controller
using AdminPanel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace AdminPanel.Controllers
{
public class LoginController : Controller
{
// GET: Login
public ActionResult Index()
{
return View();
}
[HttpPost, ValidateAntiForgeryToken]
public ActionResult Login(cUser user)
{
return Content($"Hello {user.Username}");
}
}
}
And finally my user model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace AdminPanel.Models
{
public class cUser
{
public string Username { get; set; }
public string Password { get; set; }
}
}