title: Problems with variable scope in Razor
body: <p>I'm fairly new to razor, kind of muddling my way through it to finish off some changes I made to the underlying c# code, and I'm running into a problem.</p>
  
  <p>I need to use a settings property on an underlying object to get the correct configuration file to pull an image location from. I'm trying to change a hardcoded image into a configurable one.</p>
  
  <p>What I have so far:</p>
  
  <pre><code>else
  {
  @{ 
       var prefix = Model.GetNameSpaceFromSettings();
       var configImgs = ChartColors.GetImgs(prefix);
  }
  &lt;div style='float:left;'&gt;
  &lt;img src='@Url.Content(Model.ComparisonChart(300, 250, false))' border='0' alt=''/&gt;   
  &lt;p&gt;&lt;/p&gt; 
  &lt;table width='295' cellpadding='2' cellspacing='1' border='0' class='summarygridtablebackground' align="left"&gt;                       
  &lt;tr class='summarygridbackground'&gt;
  &lt;td&gt;
  &lt;div style="float:left; width:125px;"&gt;&lt;img src='@configImgs.MyImg' border='0'&gt;&lt;/div&gt;//This is where I'm working
  &lt;/td&gt;
  &lt;/tr&gt;
  //a few more rows where I'm trying to eventually do the same thing
  &lt;/table&gt;
  &lt;/div&gt;
  }
  </code></pre>
  
  <p>This doesn't work, with the message "The name 'configImgs' does not exist in the current context."</p>
  
  <p>I read in another question that a common solution to scope problems was to put the variables into an @functions section, so I tried that, and it ended up looking like this:</p>
  
  <pre><code>else
  {
  @functions{ 
        string prefix = Model.GetNameSpaceFromSettings();
        Images configImgs = ChartColors.GetImgs(prefix);
  }
  </code></pre>
  
  <p>This one fails with a message pair, "An object is required for the non-static field, method, or property 'System.Web.Mvx.WebViewPage.Model.get" (I tried referencing it with 'this' as well, and it said that 'this' was not available in the current context) and "A field initializer cannot reference the non-static field, method, or property 'ASP.Myfile.prefix'"</p>
  
  <p>I could really use some help here, thanks.</p>