I try pass model data between two Razor pages, data is not string or bool or int data that i want pass to second page is a model, i do taht with this way,
public class AskLibrarian { public int Id { get; set; } public string FullName { get; set; } public string Subject { get; set; } public string Email { get; set; } public string Text { get; set; } public string UserIp { get; set; } public DateTime CreateDate { get; set; } public bool ReadIt { get; set; } public bool Answer { get; set; } public string reciptCode { get; set; } } And on Get method pass data with this way:
[BindProperty] public AskLibrarian AskLibrarian { get; set; } public async Task<IActionResult> OnPostQuestionAsync() { if (!ModelState.IsValid) { return Page(); } AskLibrarian.Answer = false; AskLibrarian.CreateDate = DateTime.Now; AskLibrarian.ReadIt = false; string userIp = $"{ HttpContext.Connection.RemoteIpAddress}"; if (string.IsNullOrEmpty(userIp)) { userIp = "127.0.0.1"; } AskLibrarian.UserIp = userIp; string rndNuber = Business.RandomNumberForQuestion.randCode; AskLibrarian.reciptCode = rndNuber; await _emailSenderService.SendEmailAsync(AskLibrarian.Email, AskLibrarian.FullName, rndNuber); _context.AskLibrarians.Add(AskLibrarian); await _context.SaveChangesAsync(); Message = "your message sended"; //return RedirectToPage("/Subfolder/Index", new { SFId = 7 }); return RedirectToPage("/Subfolder/AskLibrarianCode", new { asklib = AskLibrarian }); } In post method in second page, like to get data on this way:
public void OnGet(Model.AskLibrarian asklib) { askLibrarianVM = new AskLibrarianVM { Answered = false, CreateDate = asklib.CreateDate, LastUpdate = asklib.CreateDate, RandomeCode = asklib.reciptCode, Status = false, }; } But asklib is empty ,I set a breakpoint at end of Get method and I sow that asklib if filled with valid values but in post method when i try to get data, asklib is empty what is my mistake
Session. Here you can save data only for that user.