I have an Page called Page1.
Inside of OnGet(string parameter1)
I check a parameter, and in some case want to route the user to another Page.
The Page is located here:
Pages/App/App.cshtml
I have tried this:
this.RedirectToPage("/App/App");//
But the user does not get redirected. It just shows the same page as expected if the redirect was not there. I want them to see the App page.
So how do I redirect to the App page?
This is what worked:
public async Task<IActionResult> OnGet(string web_registration_key)
{
//Check parameter here
if(doRedirect)
{
return RedirectToPage("/App/App")
}
}
return null;
}
The return null seems odd, but not sure what else to return.
I used the return Page();
Here is an example from on of my projects:
public IActionResult OnGet(int id)
{
var MenuItemFromDb = _db.MenuItem.Include(m => m.CategoryType).Include(m => m.FoodType)
.Where(x => x.Id == id).FirstOrDefault();
if (MenuItemFromDb == null)
{
return RedirectToPage("./Index");
}
else
{
ShowCart(id);
return Page();
}
}
private void ShowCart(int id)
{
var MenuItemFromDb = _db.MenuItem.Include(m => m.CategoryType).Include(m => m.FoodType)
.Where(x => x.Id == id).FirstOrDefault();
CartObj = new ShoppingCart()
{
MenuItemId = MenuItemFromDb.Id,
MenuItem = MenuItemFromDb
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With