Home > Blockchain >  Redirecting with slug in Razor Pages
Redirecting with slug in Razor Pages

Time:12-02

In Razor Pages, how can I redirect to a URL that contains slugs?

For example, the code below takes me to the URL that contains rootValue:

return RedirectToPage("/EmailConfirmation", new {email = command.Email});

The output is like this: https://localhost:5001/EmailConfirmation/[email protected]

But how can I use Razor Pages commands to go to the following URL that contains slugs? https://localhost:5001/[email protected]

CodePudding user response:

You could use RedirecToAction,

return RedirectToAction("EmailConfirmation", new { email = command.Email });

Given that you have an action named EmailConfirmation like,

public IActionResult EmailConfirmation([FromQuery] string email)
{  
   //your code
   return View();
}

CodePudding user response:

If you want to go to the following url:

https://localhost:5001/[email protected]

You can try to use PageModel.Redirect(String) Method:

string queryString = "?email="   command.Email;
return Redirect("/EmailConfirmation" queryString);
  • Related