@{ Node tempNode = new Node(1272); string author = ""; <select name="author" id="author"> <option value=""></option> @{Dictionary<String, bool> usedAuthors = new Dictionary<String, bool>();} @foreach (var db in @tempNode.ChildrenAsList){ foreach (var c in db.ChildrenAsList){ if (c.GetProperty("author") != null && !usedAuthors.ContainsKey(c.GetProperty("author").ToString().Trim()) ){ if (c.GetProperty("author").ToString() != "" && c.GetProperty("author").ToString() != author){ <option value="@c.GetProperty("author").ToString()" > @c.GetProperty("author").ToString() </option> author = c.GetProperty("author").ToString(); } } usedAuthors[c.GetProperty("author").ToString().Trim()] = true; } } </select> }
this scropt creates an option for each child under new Node(1272)
it workd perfectly untill i had too many items under new Node(1272)and i started to arrange it's items in a Content folders, since then I'm getting an "Error loading Razor Script AutorSelectBox.cshtml Object reference not set to an instance of an object" message.
Searching Script
the second problem is that the searching script as well does'nt identify any item i moved into these Content-Folders. the script:
I'm new with this scripting language and cant find a solution. I think the key is to define the actions to work for each children of the children that now defined as edge item.
fixing a searching script
hi, my first time here :) hoping for a good expirience
I have 2 problems with 2 scripts that caused by creating a ContentFolder with this tutorial.
author select Box
I use to work with a developer that writed this script for me for the searching part of my site:
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.NodeFactory
@{
Node tempNode = new Node(1272);
string author = "";
<select name="author" id="author">
<option value=""> </option>
@{Dictionary<String, bool> usedAuthors = new Dictionary<String, bool>();}
@foreach (var db in @tempNode.ChildrenAsList){
foreach (var c in db.ChildrenAsList){
if (c.GetProperty("author") != null && !usedAuthors.ContainsKey(c.GetProperty("author").ToString().Trim()) ){
if (c.GetProperty("author").ToString() != "" && c.GetProperty("author").ToString() != author){
<option value="@c.GetProperty("author").ToString()" > @c.GetProperty("author").ToString() </option>
author = c.GetProperty("author").ToString();
}
}
usedAuthors[c.GetProperty("author").ToString().Trim()] = true;
}
}
</select>
}
this scropt creates an option for each child under new Node(1272)
it workd perfectly untill i had too many items under new Node(1272)and i started to arrange it's items in a Content folders, since then I'm getting an "Error loading Razor Script AutorSelectBox.cshtml Object reference not set to an instance of an object" message.
Searching Script
the second problem is that the searching script as well does'nt identify any item i moved into these Content-Folders. the script:
@inherits umbraco.MacroEngines.DynamicNodeContext
@using WebMatrix.Data
@using umbraco.NodeFactory
@{
string wherestr = "";
string searchString = Request["search"];
if (searchString == null){
searchString = "";
}
string CategoryNodeID = Request["CategoryNodeID"];
if(CategoryNodeID != null && CategoryNodeID != "" && CategoryNodeID != "1272"){
wherestr = wherestr + " and CategoryNodeID=" + CategoryNodeID + " ";
}
string SubCategoryNodeID = Request["SubCategoryNodeID"];
if(SubCategoryNodeID != null && SubCategoryNodeID != ""){
wherestr = wherestr + " and SubCategoryNodeID=" + SubCategoryNodeID + " ";
}
string author = Request["author"];
if (author != null && author != "" ){
wherestr = wherestr + " and SubCategoryNodeID= " + author + " ";
}
/* */
// string NodeId = Request["search"];
var db = Database.Open("ToraConnectionString");
string sqlstr = " SELECT * FROM KB_full_search WHERE ([xml] LIKE N'%" + searchString + "%' or SubCategoryNodeName LIKE N'%" + searchString + "%' or CategoryNodeName LIKE N'%" + searchString + "%') " + wherestr;
// " and DbCategoryNodeID=1273 ";
var Categorylist = db.Query(sqlstr);
}
<div>@sqlstr </div>
@foreach (var c in Categorylist)
{
int tempNodeID = int.Parse(c.DBSubCategoryNodeID.ToString());
Node tempNode = new Node(tempNodeID);
@* <div>
<div class="right"> @c.DBCategoryNodeName : </div>
<div class="right"> @c.DBSubCategoryNodeName :</div>
<div class="right"> @c.SubCategoryNodeName :</div>
<div class="right"> @c.CategoryNodeName *</div>
@tempNode.GetProperty("text")
</div>
<div class="clearfix"></div>*@
int DBCategoryNodeID = int.Parse(c.DBSubCategoryNodeID.ToString());
switch (DBCategoryNodeID)
{
case 1276:
if (tempNode.GetProperty("questionText") != null)
{
string bodyText = tempNode.GetProperty("questionText").ToString();
<div>
<h3><a href="@umbraco.library.NiceUrl(tempNodeID)">@c.DBSubCategoryNodeName - ---------------------------- @Html.Raw(c.DBCategoryNodeName) </a></h3>
@if (bodyText.Length > 100)
{
bodyText = bodyText.Substring(0, 100);
}
<p>@Html.Raw(bodyText)</p>
</div>
}
break;
default:
if (tempNode.GetProperty("text") != null)
{
string bodyText = tempNode.GetProperty("text").ToString();
<div>
<h3><a href="@umbraco.library.NiceUrl(tempNodeID)">@c.DBSubCategoryNodeName - ---------------------------- @Html.Raw(c.DBCategoryNodeName) </a></h3>
@if (bodyText.Length > 100)
{
bodyText = bodyText.Substring(0, 100);
}
<p>@Html.Raw(bodyText)</p>
</div>
}
break;
}
}
I'm new with this scripting language and cant find a solution. I think the key is to define the actions to work for each children of the children that now defined as edge item.
any ideas? :-\
is working on a reply...