I've been learning .NET and I decided to try MVC by starting a simple login page. I have 2 text fields in a form that are passed to a overloaded controller view method by HttpPost.
The issue is when I have fieldset around both of the inputs for username/password they won't pass the value through what I'm assuming is the HttpPost. My actual logic I think is sound since when I remove the fieldsets from the form it works fine and passes the correct values.
My question is why are the fieldsets messing up? Is there a work around or should I not be using fieldsets in this? Here's my form and my HttpPost controller.
<div>
@ViewBag.FailedLogin
<form id="loginForm" action="/Login/Login" method="post">
<h1>Log In</h1>
<fieldset>
<input id="un" type="text" placeholder="Username" autofocus required>
<input id="pw" type="password" placeholder="Password" required>
</fieldset>
<fieldset id="actions">
<input type="submit" value="Log in">
@*<a href="">Forgot your password?</a> <a href="">Register</a>*@
</fieldset>
</form>
</div>
And my overloaded controller method
[HttpPost]
public ActionResult Login(string un, string pw)
{
Models.RoadsEntities dbcon = new Models.RoadsEntities();
var user = dbcon.tblUsers.Where(m => m.UserName == un&& m.Password == pw).FirstOrDefault();
if (user != null)
return View("loginChild");
else
{
ViewBag.FailedLogin = "Incorrect user ID or password";
return View("Login");
}
}
Thank you for the help.