title: MVC Html custom Helper cut spaces
body: <p>I wrote helper</p>
  
  <pre><code>  public static class TestHelper
    {
      public static string Test(this HtmlHelper helper)
      {
          var writer = new HtmlTextWriter(new StringWriter(), string.Empty);
          //writer.InnerWriter.NewLine = string.Empty;
          //writer.NewLine = string.Empty;
          writer.RenderBeginTag(HtmlTextWriterTag.Ul);  //&lt;ul&gt;
          for (int i = 0; i &lt; 5; i++ )
          {
            RenderRow(helper, writer, i);
          }
          writer.RenderEndTag();                        //&lt;/ul&gt;
          return writer.InnerWriter.ToString();
      }
  
      private static void RenderRow(HtmlHelper helper, HtmlTextWriter writer, int i)
      {
        writer.RenderBeginTag(HtmlTextWriterTag.Li);
        writer.Write(i);
        writer.RenderEndTag();
      }
    }
  </code></pre>
  
  <p>and use it the same way:</p>
  
  <pre><code>@Html.Test()
  </code></pre>
  
  <p>but in result I see html tags in browser. The problem is a space before the first tag:</p>
  
  <pre><code>&lt;ul&gt; &lt;li&gt;0&lt;/li&gt;&lt;li&gt;1&lt;/li&gt;&lt;li&gt;2&lt;/li&gt;&lt;li&gt;3&lt;/li&gt;&lt;li&gt;4&lt;/li&gt; &lt;/ul&gt; 
  </code></pre>
  
  <p>there is a symbol with code 020h before "ul".
  I tryed:</p>
  
  <p>1) in the Test class:</p>
  
  <pre><code>return writer.InnerWriter.ToString().Trim();
  </code></pre>
  
  <p>2) in the cshtml file:</p>
  
  <pre><code>@Html.Test().Trim()
  </code></pre>
  
  <p>3) Tryed to change writer settings</p>
  
  <pre><code>writer.InnerWriter.NewLine = string.Empty;
  writer.NewLine = string.Empty;
  </code></pre>
  
  <p>But all these without positive result (third step partly clean the code).
  Is here any way to have html code without tabs, spaces, end of string etc?</p>