title: Function to display a DateTime string or an empty string
body: <p>I tried to create a view helper which takes a DateTime object and returns a string. If the DateTime object equals a new DateTime(0), the function returns an empty string. Otherwise return a formatted DateTime string. This works so far. </p>
  
  <pre><code>public static string DateTimeOrEmpty(this HtmlHelper htmlHelper, DateTime dateTime)
  {
      return dateTime.ToString().Equals(new DateTime(0).ToString()) 
          ? String.Empty 
          : dateTime.ToString("{0:g}");
  }
  </code></pre>
  
  <p>The Problem is, that I'd like to pass the format ("{0:g}") as a parameter:</p>
  
  <pre><code>public static string DateTimeOrEmpty(this HtmlHelper htmlHelper, DateTime dateTime, string format)
  {
      return dateTime.ToString().Equals(new DateTime(0).ToString()) 
          ? String.Empty 
          : dateTime.ToString(format);
  }
  </code></pre>
  
  <p>But it doesn't work properly. If I call the helper from my view</p>
  
  <pre><code>&lt;%: Html.DateTimeOrEmpty(Model.StopDate, "{0:g}") %&gt;
  </code></pre>
  
  <p>the function with "{0:g}" as parameter for "format", I get something like "{O:n. Chr.}", which is not what I expect</p>