First of all, no need to use Html.Raw on absolutely every element. Only if you know that a variable could contain some HTML then you can output the Raw HTML.
This error is probably due to some property being null, but your example is a bit too long to really figure out which one it could be. Add &umbDebugShowTrace=true to your querystring and scroll down into the trace to find out what line number is actually causing the error.
Don't know if this pertains to what I am trying to do, but I am have created a list of CreatorNames and now I am trying to create a link for each of them that creates a querystring that then returns me back all of their posts they have written. I feel like I am almost there. I am just stuck on this last part.
This is what I have so far, can anyone help me out? Thanks,
I have all the authors I need in a list already using the code I have. My issue is now I need all the nodes back they have created when a users clicks on their name.
So when a user clicks on their name, it returns them back to my @baseNode page and shows all of the nodes they have created. How would I do this?
The code I posted above should create a where clause to bring back all pages where the CreatorName equals the value passed in the QueryString field "author". So that should do it. My naming was probably confusing, it would make more sense to say this:
var pages = Model.AncestorOrSelf().Descendants().Where(predicate);
As this describes what it is doing. ie. it fetches all pages (nodes) created by that author.
Problem with Request.QueryString
I just tried to write my first cshtml razor script and end up with an error if I assign an Request.QueryString value to a variable.
The following error ocurs:
Error loading Razor Script MainNavi.cshtml
Die Laufzeitbindung kann für einen NULL-Verweis nicht ausgeführt werden.
Here is my script:
@using umbraco.MacroEngines.Library;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var strQuery = String.IsNullOrEmpty(Request.QueryString["l"]) ? "" : String.Format("?l={0}", Request.QueryString["l"].ToLower());
var strLang = String.IsNullOrEmpty(Request.QueryString["l"]) ? "EN" : Request.QueryString["l"].ToUpper();
var ulClass = String.IsNullOrEmpty(Parameter.UlClass) ? "" : String.Format(" class=\"{0}\"", Parameter.UlClass);
var parent = Model.AncestorOrSelf();
if (parent != null) {
<[email protected](ulClass)>
@foreach (var item in parent.Children) {
if (Convert.ToBoolean(item.umbracoNaviHide)==false) {
var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
<[email protected](selected)>
@{string strMenuText = item.GetProperty("menuTitle" + strLang).Value;}
<a href="@item.Url">@Html.Raw(strMenuText)</a>
@if (item.Children.Count() > 0) {
<ul>
@foreach (var subitem in item.Children) {
if (Convert.ToBoolean(subitem.umbracoNaviHide)==false) {
var selectedSub = Array.IndexOf(Model.Path.Split(','), subitem.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
<[email protected](selectedSub)>
<a href="@subitem.Url">@subitem.Name</a>
</li>
}
}
</ul>
}
</li>
}
}
</ul>
}
}
Thanks for any hint on this problem.
First of all, no need to use Html.Raw on absolutely every element. Only if you know that a variable could contain some HTML then you can output the Raw HTML.
This error is probably due to some property being null, but your example is a bit too long to really figure out which one it could be. Add &umbDebugShowTrace=true to your querystring and scroll down into the trace to find out what line number is actually causing the error.
Hi Sebastiaan
Thank you for the umbDebugShowTrace - trick. I found the empty property and now everything works.
By the way, the @Html.Raw was from the included example navigation script.
Aah, well, that only reminds me that I want to take a look at the included examples and improve them where possible. Glad you got it fixed!
Don't know if this pertains to what I am trying to do, but I am have created a list of CreatorNames and now I am trying to create a link for each of them that creates a querystring that then returns me back all of their posts they have written. I feel like I am almost there. I am just stuck on this last part.
This is what I have so far, can anyone help me out? Thanks,
string creatorList = "";
<ul>
@foreach(dynamic node in @Model.NodeById(1089).Descendants("ScienceResearchUpdatesPost").OrderBy("CreatorName"))
{
if (creatorList != node.CreatorName)
{
<li><a href="@[email protected]">@node.CreatorName</a></li>
}
creatorList = node.CreatorName;
}
</ul>
}
Assuming your authors could be anywhere in the tree you could use something like this to fetch them based on query string:
This is off top of my head and syntax might be a little wrong.
@Dan
I have all the authors I need in a list already using the code I have. My issue is now I need all the nodes back they have created when a users clicks on their name.
So when a user clicks on their name, it returns them back to my @baseNode page and shows all of the nodes they have created. How would I do this?
Thanks
The code I posted above should create a where clause to bring back all pages where the CreatorName equals the value passed in the QueryString field "author". So that should do it. My naming was probably confusing, it would make more sense to say this:
As this describes what it is doing. ie. it fetches all pages (nodes) created by that author.
is working on a reply...