【发布时间】:2018-04-02 14:44:50
【问题描述】:
我正在 Asp.Net Core 2.0 MVC 上开发一个 Web 应用程序,有一个注册模式表单将在所有页面中使用,并且无法理解我应该如何进行用户模型绑定,因为每个页面都会有自己的模型。
例如,有一个新闻页面将使用新闻模型,而在该页面上,用户将希望注册或登录(主布局中集成了两种模式表单)。
下面是注册模式的表单部分:
<form action="/Account/RegisterAccount" method="post">
@Html.AntiForgeryToken()
<div class="cfield">
<input name="username" type="text" placeholder="Username" />
</div>
<div class="cfield">
<input name="email" type="text" placeholder="E-mail address" />
</div>
<div class="cfield">
<input name="password" type="password" placeholder="Password" />
</div>
<div class="cfield">
<input type="password" placeholder="Confirm Password" />
</div>
<button type="submit">Register</button>
</form>
到目前为止,我所做的只是在没有模型的情况下提交了表单数据,但我在想也许最好找到一种方法来绑定模型,这样我也可以进行模型验证。
另外,如果有人可以就管理登录用户的最佳做法给我一个建议,那将是一个很好的帮助。
这是我在这里的第一篇文章,我对 Core 和 MVC 完全陌生。
【问题讨论】:
标签: asp.net-core asp.net-core-mvc