继承人的情景:我有一个用户对象是这样的:MVC - 部分在视图中更新模型
public class User : BaseEntity<User>, IAggregateRoot
{
public virtual string Name { get; set; }
public virtual string Username { get; set; }
public virtual string Password { get; set; }
public virtual string SecretQuestion { get; set; }
public virtual string SecretAnswer { get; set; }
public virtual DateTime LastLogin { get; set; }
}
在此对象的编辑,我将其加载到的观点,但我只是想更新一些属性(即我不想更新LastLogin属性)。在这种情况下,我会怎么做?
是创建用户视图模型的最佳策略,并且当我尝试用空的LastLogin字段更新用户对象时,nhibernate会处理这个问题吗?
在此先感谢。
编辑
事情是这样的:
public class UserViewModel
{
public string Name {get;set;}
public string UserName {get;set;}
public string Password {get;set;}
public string SecretQuestion {get;set;}
public string SecretAnswer {get;set;}
}
然后编辑:
public ActionResult Edit(int id)
{
return View(_userRepository.FindById(id));
}
[HttpPost]
public ActionResult Edit(int id, UserViewModel userViewModel)
{
try
{
//Not sure how to update the model
//with the view Model and save.
_userRepository.Update(????);
return RedirectToAction("Index");
}
catch
{
return View();
}
}
嗨安德鲁谢谢你的回复。你可以作为视图模型的例子和上面使用我的类的编辑帖子吗?它的编辑位我不确定。 – gdp 2011-05-17 21:48:21