2016-01-23 22 views
0

讓我們說我使用實體框架6和一個模型中,第一種方法在下面兩個表:如何使用IEnuernation <T>屬性添加創建和編輯視圖到模型?

enter image description here

這將創建下列代碼:

enter image description here

enter image description here

我的問題是現在,我如何在創建視圖中使用IEnumeration屬性?在Details或Delete視圖中,我只是使用Html.DisplayFor幫助器遍歷它們,但我不知道我可以用什麼來實現創建和編輯視圖的可比性。事情是這樣的:

<div class="form-group"> 
    @Html.LabelFor(model => model.MappedEmployees, htmlAttributes: new { @class = "control-label col-md-2" }) 
    <div class="col-md-10"> 
     <!--Something like checkbox list with Name property of each collection property item--> 
    </div> 
</div> 

所以我最終會是這樣的:

enter image description here

+1

這比EF的MVC剃刀問題。 –

+0

您是否想要顯示所有員工,然後使用複選框選擇與帳戶關聯的人員? –

+0

是的,這是我正在努力實現... – LeonidasFett

回答

0

有關於這個問題的一些好的博客文章,他們應該在這方面對您有用:

haacked.com blog posting

Hanselman.com blog posting

我沒有測試以下,但這樣的事情:

<div class="form-group"> 
    @Html.LabelFor(model => model.MappedEmployees, htmlAttributes: new { @class = "control-label col-md-2" }) 
    <div class="col-md-10"> 

@for(int i = 0; i < model.MappedEmployees.Count; i ++) 
{ 
Html.CheckBoxFor(model => model.MappedEmployees[i], new { htmlAttributes = new { @class = "form-control" } }) 
} 

    </div> 
</div> 
+0

似乎我需要一個bool值的CheckBoxFor構造函數的表達式參數。但我不知道如何讓它工作,以便它可以從我的ICollection屬性中添加/刪除項目。 – LeonidasFett

相關問題