嗯,一個你可以快速和骯髒的東西是第一個對象傳遞給PickDatePartial
@Html.Partial("PickDatePartial", Model.First())
但是,這是不是很乾淨。我建議創建具有兩個屬性:1)整個列表,2)一個由PickDatePartial
綁定視圖模型:
public class IndexViewModel
{
public List<MyProject.Domain.Object> MyList { get; set; }
public MyProject.Domain.Object ObjectToBind { get; set; }
}
然後在你的Index
動作控制器上:
public ActionResult Index()
{
var myList = // instantiate list here
var viewModel = new IndexViewModel
{
MyList = myList,
ObjectToBind = myList.First() // or whichever you need out of that list
}
return View(viewModel);
}
當然,您需要在Index
視圖中更改模型的類型。現在Index
視圖看起來像這樣:
@model IndexViewModel
@Html.Partial("PickDatePartial", Model.ObjectToBind)
@Html.Partial("ObjectPartial", Model.MyList)
另一種選擇是將ObjectToBind更改爲int選擇指數,並通過@ Html.Partial( 「PickDatePartial」 Model.List [Model.Selection]) – 2011-04-19 21:39:23