私は自分のアプリのカスタムメンバーシップを持っていますが、それは一般的なメンバーシップとほとんど同じです。他の詳細の中で、異なるのは、Registerpostメソッドに値を渡す方法です。
これまで、ユーザー名、パスワード、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これは、Registerpostメソッドで行われる方法です。
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は空です。
私はさらにいくつかのアイデアを試しましたが、今のところ何も試していません。