Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael Friedrich 20 posts 97 karma points
    Nov 18, 2011 @ 14:51
    Michael Friedrich
    0

    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.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Nov 18, 2011 @ 14:54
    Sebastiaan Janssen
    0

    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. 

  • Michael Friedrich 20 posts 97 karma points
    Nov 18, 2011 @ 16:47
    Michael Friedrich
    0

    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.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Nov 18, 2011 @ 16:49
    Sebastiaan Janssen
    0

    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!

  • Carlos 338 posts 472 karma points
    Jun 21, 2012 @ 23:29
    Carlos
    0

    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><href="@[email protected]">@node.CreatorName</a></li>    
            }
            creatorList node.CreatorName;
          }
         </ul>
        
      }

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 21, 2012 @ 23:49
    Dan Diplo
    0

    Assuming your authors could be anywhere in the tree you could use something like this to fetch them based on query string:

    string predicate = String.Format("CreatorName=\"{0}\"", Request.QueryString["author"]);
    var authors = Model.AncestorOrSelf().Descendants().Where(predicate);

    This is off top of my head and syntax might be a little wrong.

  • Carlos 338 posts 472 karma points
    Jun 21, 2012 @ 23:54
    Carlos
    0

    @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 

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 22, 2012 @ 14:14
    Dan Diplo
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft