.NET Razor Pages: Get Query String in View or Layout

10/8/2019 4:18:28 PM

Get a query string parameter from a Razor Page Layout page or from a Razor Page View page.

From the Layout


var query_string_value = Context.Request.Query["key"];
if (!string.IsNullOrWhiteSpace(query_string_value))
{
	//do something?	
}

From the View


var query_string_value = Request.Query["key"];
if (!string.IsNullOrWhiteSpace(query_string_value))
{
	//do something?	
}