Shaokan
Shaokan

Reputation: 7694

c# mvc textboxfor for multiple strings

Is it possible to have a Html.TextBoxFor html helper bound to multiple strings? I mean, say you have one input which the user can either sign in with a username or email. Basically, something like the following:

@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 

Upvotes: 2

Views: 400

Answers (1)

pfeds
pfeds

Reputation: 2273

Don't bind the textbox to either property. Simply handle the code in an Action to check against Username and Email.

If you're creating a login form then you won't be updating either property, so there's no need to bind.

Upvotes: 1

Related Questions