2012-05-16 61 views
1

我在表中包含此值「American | African | Asian」的字段。我想從字段中獲取值並拆分文本並將其綁定到下拉列表中。我使用MVC 3創建一個htmlhelper來分割文本

到目前爲止,我有這樣一條:

public static SelectList SplitText(this HtmlHelper html, string texttosplit, string seperator) 
{ 
    return new SelectList(texttosplit.Split('|')); 
} 

但我不知道如何將它綁定在下拉列表

@Html.DropDownListFor(model => model.EM_opt1Values, @Html.SplitText(this will have an error it will not accept model => model.EM_opt1Values)) 
+0

[你有什麼嘗試?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – Iridio

+0

請看看更新的一個。 – user335160

回答

1

我認爲錯誤是資本M.

@Html.DropDownListFor(model => model.EM_opt1Values, @Html.SplitText(Model.EM_opt1Values)) 

值應該從頁面的Model完成,而不是從模型中變量y你在lambda裏面定義。我無法驗證它的ATM,但我認爲這應該做到這一點。