2011-07-03 25 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