2

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 

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

hmm that's not what I was looking for but thanks for the tip :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.