Metehanson
Metehanson

Reputation: 45

Add/pass new field to MVC Membership CreateUser

Developing MVC4 application and using Register that comes with MVC5 framework. I updated register.cshtml and added a new column called Language. I also updated the RegisterModel class to hold my value. Register model has all the values including my property (language).

Now I like to grab this values from Register Model and plug into CreateUser.

MyProperty is model.Language

[HttpPost]
publıc ActıonResult Register(RegisterModel model)
{
    Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, Guid.NewGuid(), out status)
}

What would be the best way to grab this value and store in database? I really like to store in Users table where UserID and UserName exists.

Upvotes: 0

Views: 680

Answers (1)

Craig Simon
Craig Simon

Reputation: 94

The trick is the syntax for passing the additional column(s) via the WebSecurity.CreatUserAndAccount call. Try this:

WebSecurity.CreateUserAndAccount(model.UserName,model.Password,
new {Language = model.Language
});

It's fully described here.

Upvotes: 1

Related Questions