Not MVC!
Hi all,
What am I doing wrong here...
Im trying to pass an integer value from the onPost method of a Razor Page(Scores/Create.cshtml) to the onGet method of another page(/Scores/Index.cshtml) however the value is not being preserved and I either get null or 0 when inspecting the id value in the onGet method depending on how I send the integer.
I know this works using routes as I do this on another page
<a asp-page="/Scores/Index" asp-route-id="@item.ElementId">Update scores</a>
I have tried passing the value from an entity property like in the code example below, from ViewData variable, also from a locally created integer and finally just passing an integer value itself. In all cases the value is correct in the OnPost but never gets to the onGet.
The OnPost
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.TScores.Add(TScores);
await _context.SaveChangesAsync();
return RedirectToPage("./Index","OnGet",TScores.ElementId);
}
The OnGet
public async Task OnGetAsync(int? id)
{
TElements telement = new TElements();
telement = _context.TElements.Where(a => a.ElementId == id).FirstOrDefault();
I have also tried it without setting the OnGet method name in the RedirecttoPage
I am expecting to get the value of id in the onGet to match TScores.ElementID passed from the onPost.
Thanks in advance
D