title: Global functions in MVC 5
body: <p>I am looking for a way where I can define global functions so I can share the implementation across multiple views. </p>
  
  <p>I was wondering where would I place them? I tried _viewStart.cshtml and /Share/_Layout.cshtml but It seems that is not working. </p>
  
  <p>I don't want to create an Extension to the <code>HtmlHelper</code> class. In my case, extensions won't work. I hate to keep copying the same function in multiple views. </p>
  
  <pre><code>@functions  {
    public static string GetColumnHeader(string columnName, string columnHeader, ISupportGridViewModel model)
    {
      return string.Format("{0} {1}", columnHeader, model.Sort == columnName ? model.SortDir == "ASC" ? "▲" : "▼" : string.Empty);
    }
  }
  </code></pre>
  
  <p>For those who commented that I should use extension. Here is the example where I am not able to to get it to work. As far as I know, Razor helpers are nothing more than extension methods and It won't work. </p>
  
  <p>Here is an example that is working</p>
  
  <pre><code>    var grid = new WebGrid(this.Model.Data);
      grid.Pager(WebGridPagerModes.Numeric);
      @grid.GetHtml(tableStyle: "table grid",
                    columns: grid.Columns(
                    grid.Column(columnName: "Time", format: (item) =&gt; MethodDefinedInView(item.EndTime))
    ))
  </code></pre>
  
  <p>Here is an example that doesn't work...</p>
  
  <pre><code>var grid = new WebGrid(this.Model.Data);
  grid.Pager(WebGridPagerModes.Numeric);
  @grid.GetHtml(tableStyle: "table grid",
                columns: grid.Columns(
                grid.Column(columnName: "Time", format: (item) =&gt; Html.ExtensionMethod(item.EndTime))
  </code></pre>
  
  <p>))</p>