I'm collecting all items that have a parent equal to a querystring in my URL. However, my code is coming up with errors. Can anyone check that I'm doing this right? Thanks.
The url contains at the end: ?Bottle=Nameofbottle (this works with other calls elsewhere)
foreach (var recipe in Model.AncestorOrSelf(Request.QueryString["Bottle"])); { do stuff with recipes }
The error: Object reference not set to an instance of an object.
I do sometimes have spaces in my querystring. So a string might look like this: All%20Products Would this effect it in anyway?
Ok, I got the querysting to work by putting it in a string first. But it's not working in my foreach and I'm not sure why:
@* get string from url *@ @{ string collect = String.Format("{0}", Request.QueryString["Bottle"]); } @collect @* THIS WORKS *@
@if (!string.IsNullOrEmpty(Request.QueryString["Bottle"])) { foreach (var recipe in Model.RecipeRepositories.AncestorOrSelf(@collect)) { @* THIS DOES NOT WORK *@ } }
Are there better ways of doing this? please do tell :) Thanks
I think the problem is that RecipeRepositories is being requested as a property (and a property doesn't have Ancestors), maybe it's a document type or a node name?
Also what value are you passing in the "Bottle" querystring variable, document type alias?
AncestorOrSelf and Request.QueryString
Hi,
I'm collecting all items that have a parent equal to a querystring in my URL. However, my code is coming up with errors. Can anyone check that I'm doing this right? Thanks.
The url contains at the end: ?Bottle=Nameofbottle (this works with other calls elsewhere)
The error: Object reference not set to an instance of an object.
I do sometimes have spaces in my querystring. So a string might look like this: All%20Products
Would this effect it in anyway?
Ok, I got the querysting to work by putting it in a string first. But it's not working in my foreach and I'm not sure why:
Are there better ways of doing this? please do tell :) Thanks
Hi James,
I think the problem is that RecipeRepositories is being requested as a property (and a property doesn't have Ancestors), maybe it's a document type or a node name?
Also what value are you passing in the "Bottle" querystring variable, document type alias?
Thanks,
Jeavon
Found the solution. You can see the correct code for the 'foreach' on another of my posts here: http://our.umbraco.org/forum/developers/razor/44701-Collect-items-from-variable-repository-name
is working on a reply...