Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I am using the following code to get a query string from the address bar..
var eventid = HttpContextAccessor.HttpContext.Request.Query["event"];
I am then trying to use the result to get page content....
var page = UmbracoContext.Content.GetById(eventid);
But it seems as though it doesn't like the fact that eventid is a string and I cannot seem to convert the string to an integer whatever I try.
Any ideas would be greatly appreciated.
I am using Umbraco 12
Thanks
Hi @Paul,
You can do the following:
// if you want to have int as an output
int eventid = int.Parse(HttpContextAccessor.HttpContext.Request.Query["event"].ToString());
// output comes back as string
var eventid = HttpContextAccessor.HttpContext.Request.Query["event"].ToString();
// Umbraco.Content() takes both string and int
IPublishedContent page = Umbraco.Content(eventid);
Hope this helps.
Cheers
Fantastic. Worked perfectly.
Thankyou
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Query string to node id
Hi,
I am using the following code to get a query string from the address bar..
I am then trying to use the result to get page content....
But it seems as though it doesn't like the fact that eventid is a string and I cannot seem to convert the string to an integer whatever I try.
Any ideas would be greatly appreciated.
I am using Umbraco 12
Thanks
Hi @Paul,
You can do the following:
// if you want to have int as an output
int eventid = int.Parse(HttpContextAccessor.HttpContext.Request.Query["event"].ToString());
// output comes back as string
var eventid = HttpContextAccessor.HttpContext.Request.Query["event"].ToString();
// Umbraco.Content() takes both string and int
IPublishedContent page = Umbraco.Content(eventid);
Hope this helps.
Cheers
Fantastic. Worked perfectly.
Thankyou
is working on a reply...