我正在寻找一个双重用途登录/注册表单的可扩展实现,它是为MSofts MVC3编写的。
这有点棘手,因为两者有不同的验证要求。
回应意见的一些细节:
properly
发布于 2011-11-28 22:49:15
这不是一个困难的问题。您只需在视图中创建两种不同的表单,一种是发送到您的注册方法,另一种是发布到您的Login方法。因为每个表单都发布到不同的Action方法,所以它们使用不同的模型,从而进行不同的验证。
示例:
@using LoginRegisterModel
...
@using (Html.BeginForm("Register", "Account")) {
... Your Register form
<input type="submit"/>
}
@using (html.BeginForm("Login", "Account")) {
... Your login form
<input type="submit"/>
}在您的控制器中:
[HttpPost]
public ActionResult Register(RegisterModel model) {
// do your registration
}
[HttpPost]
public ActionResult Login(LoginModel model) {
// do your login
}在你们的模型中:
public LoginRegisterModel {
public LoginModel {get; set;}
public RegisterModel {get; set;}
}通常更容易将每个表单放在一个分部视图中,然后您只能将相关的模型传递给这个部分。
发布于 2011-11-28 22:14:04
因此,将注册表单和注册表单中的默认代码放在一个现成的MVC应用程序中,并将它们放到一个名为“dualPurposeLoginSignup”的新视图中,并将其用作您的登录页面。一旦你这样做了,你现在应该有你想要的东西了。
祝你的项目好运。
https://stackoverflow.com/questions/8302420
复制相似问题