私は自分のアプリのカスタムメンバーシップを持っていますが、それは一般的なメンバーシップとほとんど同じです。他の詳細の中で、異なるのは、Register
postメソッドに値を渡す方法です。
これまで、ユーザー名、パスワード、firstName、...、stateをすべて文字列として(質問には関係ありませんが)、次のようにメソッドパラメーターに含めていました。
public ActionResult Register(string userName, string password, string confirmPassword, string firstName, string lastName, string address, string city, string state, string zip)
手元の問題はState
パラメータです。これまでのように、テキストボックスからではなくドロップダウンから渡してほしいと思います。
ドロップダウンにデータを入力するためのモデルを作成しました。
public class State
{
public int StateID { get; set; }
public string StateName { get; set; }
}
SelectList
そして、私のRegister View
方法に適切に追加しました。
public ActionResult Register()
{
ViewBag.StateID = new SelectList(db.States, "StateID", "StateName");
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View();
}
次に、を変更し、ヘルパーRegister
View
の代わりにドロップダウンを作成しました。Html.TextBoxFor
@Html.DropDownList("StateID", (SelectList)ViewBag.StateID, new { @class = "ddl" })
username
とを除くこれらのパラメータはすべてプロパティpassword
に保存されることに注意してください。User Profile
これは、Register
postメソッドで行われる方法です。
ProfileBase _userProfile = ProfileBase.Create(userName);
_userProfile.SetPropertyValue("FirstName", firstName);
_userProfile.SetPropertyValue("LastName", lastName);
_userProfile.SetPropertyValue("Address", address);
_userProfile.SetPropertyValue("City", city);
_userProfile.SetPropertyValue("State", state);
_userProfile.SetPropertyValue("Zip", zip);
_userProfile.Save();
最後に、問題はそれが保存されないことです。そのユーザーのState
プロパティProfile
は空です。
私はさらにいくつかのアイデアを試しましたが、今のところ何も試していません。