내 앱에 대한 맞춤 멤버십이 있습니다. 일반적인 앱과 거의 같습니다. 무엇보다 다른 점은 내 Register
게시 방법에 값을 전달하는 방법입니다.TextBox에서 DropDownList로 변경
지금까지 나는, 비밀번호, 이름은 ..., 상태는 모두 문자열로 같은, 내 메서드 매개 변수에 사용자 이름 (질문에 대한 더하지만 관련이없는이의)했다 :
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; }
}
그리고 내 Register View
방법에 적절한 SelectList
을 추가했다.
public ActionResult Register()
{
ViewBag.StateID = new SelectList(db.States, "StateID", "StateName");
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View();
}
그럼 난 Register
View
을 변경했습니다, 그리고 Html.TextBoxFor
도우미 대신 드롭 다운을했다. 이 모든 매개 변수 username
및 password
을 제외
@Html.DropDownList("StateID", (SelectList)ViewBag.StateID, new { @class = "ddl" })
참고, 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
입니다.
나는 여러 가지 아이디어를 시도했지만 지금까지는 아무 것도 시도하지 않았습니다.
감사합니다. +1 또한 정확합니다. – rexdefuror
먼저 답을 써야하지만, 몇 가지 추가 설명이 있으면 좋을 것입니다 =) –