任何人都可以幫我弄清楚在我的視圖中顯示模型的查找屬性的標準方式是什麼?如何使用Asp.Net MVC 3應用程序的關係屬性?
比方說,我有以下型號:
public class ProfileModel()
{
public int Id { get; set; }
public string Description { get; set; }
}
public class UserModel()
{
public int Id { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public ProfileModel Profile { get; set; }
}
我UserController中有下列行爲:
[HttpGet]
public ActionResult Create()
{
return View(new UserModel());
}
[HttpPost]
public ActionResult Create(UserModel model)
{
//Do something
}
應該如何我的看法是什麼樣子?我發送一個空的UserModel。我希望用戶在選擇列表中選擇一個配置文件。
對於使用視圖包將配置文件選項列表發送到選擇列表的複雜和大型應用程序,它是一個標準嗎?
我應該爲ProfileModel創建一個自定義編輯器嗎?
我其實知道我有很多選擇。但我想知道什麼是大型應用程序的最佳解決方案。我很難弄清楚的一件事是,我需要一種方法來顯示選擇列表,但仍然允許模型活頁夾在發佈數據時創建配置文件的實例,以便我可以將其保存到數據庫。
我很欣賞任何指導!謝謝。
你在找什麼是「部分視圖」。看看這裏:http://www.mikesdotnetting.com/Article/105/ASP.NET-MVC-Partial-Views-and-Strongly-Typed-Custom-ViewModels – 2013-03-10 20:26:24