大佬教程收集整理的这篇文章主要介绍了asp.net MVC 4通过不同的形式发布多个,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在MVC视图中,您可以根据需要拥有任意数量的表单,其中包含多个字段。为简单起见,请使用单个视图模型以及页面上每种表单所需的所有属性。请记住,您将只能访问您提交的表单中的表单字段数据。因此,如果您在同一页面上有登录表单和注册表单,则可以这样进行:
LoginRegisterviewmodel.cs
public class LoginRegisterviewmodel {
public String LoginUsername { get; set; }
public String Loginpassword { get; set; }
public String RegisterUsername { get; set; }
public String Registerpassword { get; set; }
public String RegisterFirstname { get; set; }
public String RegisterLastname { get; set; }
}
YourVIEwname.csHTML
@model LoginRegisterviewmodel
@using (HTML.beginForm("Login", "Member", FormMethod.Post, new {})) {
@HTMl.LabelFor(m => m.LoginUserName)
@HTMl.TextBoxFor(m => m.LoginUserName)
@HTMl.LabelFor(m => m.Loginpassword)
@HTMl.TextBoxFor(m => m.Loginpassword)
<input type='submit' value='Login' />
}
@using (HTML.beginForm("Register", "Member", FormMethod.Post, new {})) {
@HTMl.LabelFor(m => m.RegisterFirstName)
@HTMl.TextBoxFor(m => m.RegisterFirstName)
@HTMl.LabelFor(m => m.RegisterlastName)
@HTMl.TextBoxFor(m => m.RegisterlastName)
@HTMl.LabelFor(m => m.RegisterUserName)
@HTMl.TextBoxFor(m => m.RegisterUserName)
@HTMl.LabelFor(m => m.Registerpassword)
@HTMl.TextBoxFor(m => m.Registerpassword)
<input type='submit' value='Register' />
}
@H_343_2@memberController.cs[httpGet]
public ActionResult LoginRegister() {
LoginRegisterviewmodel model = new LoginRegisterviewmodel();
return vIEw("LoginRegister", model);
}
[httpPost]
public ActionResult Login(LoginRegisterviewmodel model) {
//do your login code here
}
[httpPost]
public ActionResult Register(LoginRegisterviewmodel model) {
//do your registration code here
}
别忘了,在调用BeginForm时,您传递的控制器名称不带“ Controller”:
@using (HTML.beginForm("Login", "Member", FormMethod.Post, new {}))
代替:
@using (HTML.beginForm("Login", "MemberController", FormMethod.Post, new {}))
以上是大佬教程为你收集整理的asp.net MVC 4通过不同的形式发布多个全部内容,希望文章能够帮你解决asp.net MVC 4通过不同的形式发布多个所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。