我是ASP.NET Core的新手,我试图使用“提交”按钮将数据从razer视图发送到我的控制器。我之前曾经尝试过使用location.href选项,现在我正在尝试表单路由。我确定这是我忽略的小事。可能是我没有razer form构造函数。
View
@model WebApplication1.Models.UserModel
@{
Layout = null;
}
<!DOCTYPE html>
<style>
</style>
<html>
<head>
<title>Login Page</title>
</head>
<body>
<div>
<div align="center">
<img src="~/images/login_stock_photo.jpg" />
</div>
<form asp-action="MainMenu" asp-controller="Home">
<div align="center">
<p>
UserName:
</p>
@Html.TextBoxFor(m => m.UserName)
<br />
<p>
Password:
</p>
@Html.PasswordFor(m => m.PassWord)<br /><br />
<div><input type="button" id="cancelButton" name="cancelButton" value="Cancel" /> <input type="button" id="submitButton" name="submitButton" value="Submit" /> </div>
</div>
</form>
</div>
</body>
</html>
控制器
[HttpPost]
public IActionResult MainMenu(UserModel Model)
{
DataLayer dl = new DataLayer();
//bool UserExists = false;
if (dl.CheckForExistingUser(Model.UserName))
return View("MainMenu");
else
return View("Index");
}