我在想,如果我有這樣一個模型類:數組類型屬性的MVC模型DisplayFormat?
public class Contact
{
public string Name { get; set; }
public string[] Emails { get; set; }
}
在我看來,我用DisplayFor,所以它並顯示所有郵件,但只是作爲一個字符串。
@Html.DisplayFor(modelItem => item.Emails)
約翰@ gmail.comjohn @ hotmail.comjohn @ microsoft.com
是否有某種DisplayFormat屬性的,我可以適用於電子郵件財產, 以便它會顯示所有電子郵件單個聯繫,用逗號分隔,就像這樣:
[email protected],[email protected],[email protected]
真的不希望使用的foreach(VAR電子郵件的型號.Email)在我看來這個簡單的操作。
謝謝。
嘗試加入適當的編程語言的標籤。在PHP中,我會使用像implode(電子郵件,','),我覺得這種語言有類似的功能 – Pevara 2012-08-03 18:41:01
你可以創建一個編輯器模板。檢查了這一點:http://coding-in.net/asp-net-mvc-3-how-to-use-editortemplates/ – 2012-08-03 18:48:58
謝謝安德烈,我也會編輯太:) – monstro 2012-08-03 23:49:10