繼承人的情景:我有一個用戶對象是這樣的: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