2012-12-07 18 views
0

我看到「不包含...的定義」錯誤。如何在ASP.Net MVC 3中使用@ Html.ListBoxFor方法?

這裏是查看

 @model Variant.SystemV.Web.Models._TaggingVM 

     @Html.ListBoxFor(x=>x.Tags, Model.SelectedTags, new { @class = "chzn-select", data_placeholder = "Select Tag(s)...", style = "width: 500px" }) 

代碼這裏是我的模型

public class _TaggingVM 
{ 
    public IEnumerable<Tag> SelectedTags { get; set; } 
    public IEnumerable<Tag> Tags { get; set; } 
    public Article Article { get; set; } 
} 
+1

如何定義標籤? –

回答

3

這是因爲Html.ListBoxFor()擴展需要的IEnumerable<SelectListItem>的參數類型,可能在您的視圖模型的財產沒有實現它。

您可以創建視圖中的項目是這樣的:

@Html.ListBoxFor(x => x.SelectedTags, new SelectList(Model.Tags, "Id", "Text")) 

它假定你有你的標籤類名爲Id的屬性和文本。你也可以在表達式中使用SelectedTags屬性。它會確保您在表單發佈後收回。

相關問題