c# - ASP.NET Razor 页面模型绑定不起作用
问题描述
我在剃须刀页面上有以下表格:
<form method="post">
<table>
<tr>
<td style="padding-bottom: 10px;" class="login-entry">User Name</td>
<td style="padding-bottom: 10px;"><input type="text" asp-for="LoginName" class="logins" autocomplete="off" /></td>
</tr>
<tr>
<td style="padding-bottom: 10px;" class="login-entry">Password</td>
<td style="padding-bottom: 10px;"><input type="password" asp-for="Password" class="logins" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:right;"><input type="submit" value="login" /></td>
</tr>
</table>
</form>
然后,在我的 PageModel 中,我有两个属性和 OnPostAsync:
public string LoginName { get; set; }
public string Password { get; set; }
public async Task<IActionResult> OnPostAsync()
{
// Login code here
}
问题是当我调试页面时,输入用户名和密码,然后单击登录,在 OnPostAsync 方法中,属性 LoginName 和 Password 都为空。
有没有人知道为什么这不起作用?或者,由于我是 Razor 页面的新手,至少有一种方法可以在它们不起作用时追踪这些东西?任何帮助将非常感激。
解决方案
推荐阅读
- mongodb - 如何让 mongod 默认从 /bin/mongod.cfg 加载配置?
- mysql - MySQL 触发器与 If 循环和信号
- c++ - 使用自定义反射将对象序列化为 JSON
- javascript - 如何访问映射 json 数组并通过 id 搜索对象并更改该对象中的值
- vba - Excel在匹配单元格时返回整行
- google-admin-sdk - 使用 Admin SDK 自动将成员添加到 google 组(G-suite)的问题
- maven - maven依赖:仅列出第一级
- java - eclipse java中编码的UTF-8代码和不可读的字符
- javascript - 如何通过直接传入对象来使用 react this.setState 更新状态
- javascript - XSLT如何仅对XML文档的字符串节点中的数值进行排序