title: MVC - Lazy load 1 string in multiple places
body: <p>I have recently added some search functionality to my application. It works well, however there is one item, called a <code>Folder</code>, that gets searched on that requires me to make a few web service calls. I return a maximum of 100 items at a time, and if all 100 items are specifically this type and require 3 or 4 web service calls each, it takes up to 30 seconds to get the information.</p>
  
  <p>The bit of information that I am getting is a <code>Path</code>. The <code>Path</code> is the same as a file path on a PC and for every level a new web service call is made. If I remove the code to get this path for each item that is returned, I can get the results to the user in about 2 - 3 seconds with 100 results. This is on my development machine so I am hoping a little faster in production.</p>
  
  <p>What I am trying to do is get the <code>Path</code> for each <code>Folder</code> after it has been loaded on the screen. This way the majority of the information is already there for the user to see, in an acceptable amount of time, and the <code>Path</code> loads a second or two later.</p>
  
  <p>What I have so far is a method in my controller that will return the <code>Path</code> as a string:</p>
  
  <pre><code>    [HttpGet]
      public string _SearchGetFolderPath(int folderID)
      {
          using (SA sa = new SA())
          using (IRWS irws = new IRWS(sa.Ticket))
          {
              return irws.getFolderPathfromFolderID(folderID);
          }
      }
  </code></pre>
  
  <p>In the above method, the SA object is a user identity for the web service and the IRWS Object is where I am keeping my web service calls.</p>
  
  <p>Then I have this in my view:</p>
  
  <pre><code>@*Display Each Returned Result*@
          @foreach (var item in Model)
          {
              &lt;div class="panel panel-default"&gt;
                  &lt;div class="panel-heading clearfix"&gt;
                      &lt;h3 class="panel-title pull-left"&gt;@(item.Name)&lt;/h3&gt;
                      &lt;span class="pull-right"&gt;@item.AspectType.AspectName&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;div class="panel-body"&gt;
                      &lt;dl class="dl-horizontal"&gt;
                          @foreach (var value in item.FieldValues)
                          {
                              &lt;dt&gt;@value.FieldName&lt;/dt&gt;
                              @*Test if Item is a Folder and Field is Path*@
                          if (item.AspectType.AspectTypeID == -10 &amp;&amp; value.FieldName.Contains("Path"))
                          {
                              /*Folder Path - get path*/
                              //   HERE IS WHERE I WOULD LIKE TO LAZY LOAD THE PATH
                          }
                          else if (false)
                          {
  
                          }
                          else
                          {
                              &lt;dd&gt;@value.FieldValue&lt;/dd&gt;
                              }
  
                          }
                      &lt;/dl&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;br /&gt;
          }
  </code></pre>
  
  <p>I want this to work similarly to how another part of my application works. Each <code>Folder</code> has a page that gives more information and I use Telerik for all my UI so I lazy load the <code>Folder</code>'s children in a <code>Panel Bar</code> (<a href="http://demos.telerik.com/aspnet-mvc/panelbar/ajax" rel="nofollow noreferrer">http://demos.telerik.com/aspnet-mvc/panelbar/ajax</a>).</p>
  
  <p>Any ideas or suggestions are much appreciated. Thanks.</p>