2013-10-03 26 views

回答

7

應用DisplayFormat屬性的NullDisplayText屬性相關視圖模型成員。

[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "-")] 
public string Name { get; set; } 

注意,DisplayFormat屬性旨在與模板傭工如EditorForDisplayFor(這聽起來像你正在做的)一起使用。

3

您可以創建自己的顯示模板並從那裏控制行爲。

@model string 

@if(Model == null){ 
    // your behavior here. 
} 
else { 

} 
相關問題