简体   繁体   中英

How can I pass 'Query Params' from a .razor page to .cshtml page in ASP.NET Core Blazor

Problem

I am trying to pass Query Params from a razor page to login.cshtml page. But I am not able to receive the Query Params

Methodology

I have razor component ForgetPassword.razor . It has a function UpdatePassword which is given below:

private async Task UpdatePassword()
{

   //The logic to be updated password will be implemented here
    .
    .
    .           
   //After user password has been updated then we need to redirect to login.cshtml page with a query param. I am using NavigationManager to redirect to login.cshtml page

    var query = new Dictionary<string, string> { { "message", "The password was successfully changed" } };
    _navManager.NavigateTo(QueryHelpers.AddQueryString("/login", query));           
}

Now when I am directed to the login.cshtml page. I am using the function OnGet to receive parameters. When I am directed towards the login.cshtml page through ForgetPassword.razor . The function is called but the message is always null .

public async Task<IActionResult> OnGet(string message)
{

     //Some logic related to message here 
}

However If I am on login.cshtml page and manually enter QueryParams in URL tab like:

https://localhost:44372/login?message=HelloWorld

I do receive the message.

Kindly help me with this problem.

Regards

Saad

The problem has been solved. I changed the function to _navManager.NavigateTo(QueryHelpers.AddQueryString("/login", query),true);

This enables force-reload to true.

many thanks for your help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM