Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyAccountViewModel
- {
- public string Username { get; set; }
- public string LastName { get; set; }
- public string MiddleInitial { get; set; }
- public string State { get; set; }
- public string ZIP { get; set; }
- public string Telephone1 { get; set; }
- public string Telephone2 { get; set; }
- public string Email { get; set; }
- public string PreferredLanguage { get; set; }
- public int DateOfBirthDay { get; set; }
- public int DateOfBirthMonth { get; set; }
- public string NewPassword { get; set; }
- public string ConfirmNewPassword { get; set; }
- public List<QuestionAnswerPairModel> SecurityQuestionAnswers { get; set; }
- public List<SelectListItem> AllowedQuestions { get; set; }
- public List<SelectListItem> PreferredLanguageList
- {
- get
- {
- return new List<SelectListItem>
- {
- new SelectListItem { Text = "English", Value = "en", Selected = PreferredLanguage == "en"},
- new SelectListItem { Text = "Español", Value = "es", Selected = PreferredLanguage == "es"},
- };
- }
- }
- public UserRegistration ToUserRegistration()
- {
- return new UserRegistration
- {
- Username = Username,
- FirstName = FirstName,
- MiddleInitial = MiddleInitial,
- LastName = LastName,
- AddressLine1 = Address1,
- AddressLine2 = Address2,
- City = City,
- State = State,
- Zip = ZIP,
- Telephone1 = Telephone1,
- Telephone2 = Telephone2,
- Email = Email,
- PreferredLanguage = PreferredLanguage,
- DateOfBirthDate = DateOfBirthDay,
- DateOfBirthMonth = DateOfBirthMonth
- };
- }
- }
- public class QuestionAnswerPairModel
- {
- public int QuestionId { get; set; }
- public string Answer { get; set; }
- public QuestionAnswerPair ToQuestionAnswerPair()
- {
- return new QuestionAnswerPair
- {
- QuestionId = QuestionId,
- Answer = Answer,
- HasChanged = Answer != "Type your answer"
- };
- }
- }
- [HttpPost]
- public PartialViewResult UpdateMyAccount(MyAccountViewModel myAccountViewModel)
- {
- //the myAccountViewModel property has null set for all properties
- }
- $.ajax({
- url: '@Url.Action("UpdateMyAccount", "MyAccount", new {area = ""})',
- type: 'post', // type: 'POST'
- //datatype: "json",
- contentType: "application/json; charset=utf-8", // contentType: "application/json"
- data: getMyAccount(), // data: JSON.stringify(getMyAccount()) and data: JSON.stringify({'myAccountViewModel': getMyAccount()}) and data: JSON.stringify({myAccountViewModel: getMyAccount()})
- success: function() {
- makeAjaxCall(accountInfo);
- }
- });
- function getMyAccount() {
- return {
- Username: $('#Username').val(),
- FirstName: $('#FirstName').val(),
- LastName: $('#LastName').val(),
- MiddleInitial: $('#MiddleInitial').val(),
- Address1: $('#Address1').val(),
- Address2: $('#Address2').val(),
- City: $('#City').val(),
- State: $('#State').val(),
- ZIP: $('#ZIP').val(),
- Telephone1: $('#Telephone1').val(),
- Telephone2: $('#Telephone2').val(),
- Email: $('#Email').val(),
- PreferredLanguage: $('#PreferredLanguage').val(),
- DateOfBirthDay: $('#DateOfBirthDay').val(),
- DateOfBirthMonth: $('#DateOfBirthMonth').val(),
- NewPassword: $('#NewPassword').val(),
- ConfirmNewPassword: $('#ConfirmNewPassword').val(),
- SecurityQuestionAnswers: [
- {
- QuestionId: $('#originalQuestionId0').val(),
- Answer: $('#answerId0').val(),
- },
- {
- QuestionId: $('#originalQuestionId1').val(),
- Answer: $('#answerId1').val(),
- },
- {
- QuestionId: $('#originalQuestionId2').val(),
- Answer: $('#answerId2').val(),
- }
- ]
- };
- }
- {"myAccountViewModel":{"SecurityQuestionAnswers":[{},{},{}]}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement