我在Umbraco 7.2 MVC中使用自定义表(自己的表)创建了一个用户注册表单。
使用petapoco方法创建的用户注册表单。 型号代码如下所示:
[TableName("UserLogin")]
[PrimaryKey("UserId", autoIncrement = true)]
[ExplicitColumns]
public class User
{
[Column]
public string UserId { get; set;}
[Column]
[Required(ErrorMessage = "Please provide Name", AllowEmptyStrings = false)]
public string Name { get; set; }
[Column]
[Required(ErrorMessage = "Please provide Email",AllowEmptyStrings=false)]
[DataType(DataType.EmailAddress)]
[RegularExpression("^([a-zA-Z0-9_\\-\\.]+)@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$", ErrorMessage = "Email is not a valid e-mail address.")]
public string Email { get; set; }
[Column]
[Required(ErrorMessage = "Please provide Adress", AllowEmptyStrings = false)]
public string Address { get; set; }
[Column]
[RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "Entered mobile format is not valid.")]
public string Mobile { get; set; }
[Column]
[Required(ErrorMessage = "Please provide Password", AllowEmptyStrings = false)]
[DataType(DataType.Password)]
[StringLength(255, MinimumLength =6, ErrorMessage = "please enter minimum 6 character")]
public string Password { get; set; }
[Required(ErrorMessage = "Please provide Confirm Password", AllowEmptyStrings = false)]
[Compare("Password", ErrorMessage = "Confirm password dose not match.")]
[DataType(DataType.Password)]
[StringLength(255, MinimumLength = 6, ErrorMessage = "please enter minimum 6 character")]
public string UserConfirmPassWord { get; set; }
}
控制器(用户控制器)代码如下所示,用于插入
public ActionResult AddUser(User _user)
{
//Add new user
if (!ModelState.IsValid)
{
ViewBag.MessageError = "Not Successfully Registration";
return CurrentUmbracoPage();
}
var db = ApplicationContext.Current.DatabaseContext.Database;
_user.Password = Encrypt(_user.Password);//Encrypt the password
db.Insert(_user);
ViewBag.MessageSuccess = "Successfully Registration Done";
return Redirect("/home/login/");
}
数据插入和selectr工作正常,但我需要通过id编辑,更新,删除数据。
我需要控制器和视图代码进行编辑,更新删除(使用petapoco的Umbraco 7.2)。