2011-07-03 24 views
2

是否有可能有一個Html.TextBoxFor html helper綁定到多個字符串?我的意思是說,你有一個輸入,用戶可以用用戶名或電子郵件登錄。基本上,類似如下:c#mvc textboxfor多個字符串

@Html.TextBoxFor(x => x.UserName || x.Email) // this does not work obviously, 
              // but you got the idea 

model.cs

... 
[Required] 
public string UserName {get; set;} 

[Required] 
public string Email {get; set;} 
// btw, the required attribute may cause a problem therefore I can 
// remove or ignore them while validating 

回答

1

不綁定文本框要麼性能。只需處理Action中的代碼即可檢查用戶名和電子郵件。

如果你正在創建一個登錄表單,那麼你將不會更新任何屬性,所以沒有必要綁定。

+0

嗯這不是我一直在尋找,但謝謝你的提示:) – Shaokan