model
//以页面为主的用户注册模式
public class RegeditModel
{
public string ID { get; set; } [Required(ErrorMessage = "请输入用户邮箱")]
[Display(Name = "邮箱")]
[DataType(DataType.EmailAddress)]
public string Email { get; set; } [Required(ErrorMessage = "请输入密码")]
[Display(Name = "密码")]
[DataType(DataType.Password)]
[StringLength(20, ErrorMessage = "{0}在{2}位至{1}位之间", MinimumLength = 6)]
public string Pwd { get; set; } [Display(Name = "重复密码")]
[DataType(DataType.Password)]
[Compare("Pwd", ErrorMessage = "密码与重复密码必须相同")]
public string RePassword { get; set; }
}
view
@model MvcB2CBookOnlineShopping.Models.RegeditModel@{
ViewBag.Title = "testcreate";
Layout = "~/Views/Shared/_Layout.cshtml";
}<h2>testcreate</h2>@using (Html.BeginForm()) {
@Html.ValidationSummary(true) <fieldset>
<legend>RegeditModel</legend>
<div class="editor-label">
@Html.HiddenFor(model => model.ID)
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div> <div class="editor-label">
@Html.LabelFor(model => model.Pwd)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Pwd)
@Html.ValidationMessageFor(model => model.Pwd)
</div> <div class="editor-label">
@Html.LabelFor(model => model.RePassword)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.RePassword)
@Html.ValidationMessageFor(model => model.RePassword)
</div> <p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
卡在了 Controllers这里。
[HttpPost]
public ActionResult testcreate(RegeditModel Users)
{
if (ModelState.IsValid)
{
try
{
//WebSecurity.CreateUserAndAccount(Users.Email, Users.Pwd);
//WebSecurity.Login(Users.Email, Users.Pwd);
//return RedirectToAction("Index", "Home");
db.Users.Add(Users);
db.SaveChanges();
return RedirectToAction("Index");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
} }
return View(Users);
}
提示说“ db.Users.Add(Users); ”这一行 “最匹配的重载方法具有一些无效参数”。求教啊唉mvc表单
//以页面为主的用户注册模式
public class RegeditModel
{
public string ID { get; set; } [Required(ErrorMessage = "请输入用户邮箱")]
[Display(Name = "邮箱")]
[DataType(DataType.EmailAddress)]
public string Email { get; set; } [Required(ErrorMessage = "请输入密码")]
[Display(Name = "密码")]
[DataType(DataType.Password)]
[StringLength(20, ErrorMessage = "{0}在{2}位至{1}位之间", MinimumLength = 6)]
public string Pwd { get; set; } [Display(Name = "重复密码")]
[DataType(DataType.Password)]
[Compare("Pwd", ErrorMessage = "密码与重复密码必须相同")]
public string RePassword { get; set; }
}
view
@model MvcB2CBookOnlineShopping.Models.RegeditModel@{
ViewBag.Title = "testcreate";
Layout = "~/Views/Shared/_Layout.cshtml";
}<h2>testcreate</h2>@using (Html.BeginForm()) {
@Html.ValidationSummary(true) <fieldset>
<legend>RegeditModel</legend>
<div class="editor-label">
@Html.HiddenFor(model => model.ID)
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div> <div class="editor-label">
@Html.LabelFor(model => model.Pwd)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Pwd)
@Html.ValidationMessageFor(model => model.Pwd)
</div> <div class="editor-label">
@Html.LabelFor(model => model.RePassword)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.RePassword)
@Html.ValidationMessageFor(model => model.RePassword)
</div> <p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
卡在了 Controllers这里。
[HttpPost]
public ActionResult testcreate(RegeditModel Users)
{
if (ModelState.IsValid)
{
try
{
//WebSecurity.CreateUserAndAccount(Users.Email, Users.Pwd);
//WebSecurity.Login(Users.Email, Users.Pwd);
//return RedirectToAction("Index", "Home");
db.Users.Add(Users);
db.SaveChanges();
return RedirectToAction("Index");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
} }
return View(Users);
}
提示说“ db.Users.Add(Users); ”这一行 “最匹配的重载方法具有一些无效参数”。求教啊唉mvc表单
解决方案 »
- 如何用DevExpress制作MenuStrip下拉菜单栏
- richTextBox1_DragDrop拖动文件后会有个图片的问题
- 如何判断一个变量是什么类型?
- File.OpenRead()中文路径出错
- 还有,您认为C#中,窗体之间的传值,那种方法比较好,可否也给个实例?非常感
- vs2005自带的Menu控件在哪里啊
- 更新ORACLE数据库,不能更新,不知到原因
- 微软 2010 rdlc 添加空白行
- 我安装好了VS。NET 2003 也安装了MSDN 可是打开帮助之后什么也没有?
- 免费提供的.net 应用程序的安装引导程序,自动安装ie6,mdac27,.net framework,欢迎使用。
- 请人提供一个好点的实时汇率的WEB Service接口。
- 导入Excel日期格式问题
db.Users.Add(new User{..属性赋值});
*****************************************************************************
http://feiyun0112.cnblogs.com/