title: MVC Razor view 'System.OutOfMemoryException' with large value string
body: <p>I have a big JSON object which I need to pass to the view displayed in web browser. Since I can not have a Controller with an Action to return this JSON object, I thought to add the JSON object in the Razor view.</p>
  
  <ol>
  <li><p><code>@Html.Hidden("fileContent", fileContent);</code></p></li>
  <li><p><code>&lt;textarea  style="display:none"&gt;
      @fileContent
   &lt;/textarea&gt;</code></p></li>
  </ol>
  
  <p>None of the above works as the ways I expected and gives me,</p>
  
  <blockquote>
    <p>Exception of type 'System.OutOfMemoryException' was thrown. </p>
    
    <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
    
    <p>Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.</p>
  </blockquote>
  
  <p>Yes, I agreed that's better to restructure the flow in another way (<a href="https://stackoverflow.com/questions/10287153/issue-with-hidden-input-and-very-large-values-in-html-and-asp-net-mvc-3-razor/10287557#10287557">may be as Mediator suggest</a> or have an action to return the JSON object.) </p>
  
  <ol>
  <li>Is that a limitation of MVC, the maximum size we can have for a MVC view?</li>
  <li>Is this because of the IIS Express configuration?</li>
  <li>Any other way to overcome this issue? Or the best way to pass a large object to the client browser.</li>
  </ol>
  
  <p>Thank you for your time. Any help would be highly appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><em>Controller</em></p>
  
  <pre><code>var file = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/content/data.csv"));
  ViewData.Add("file", file);
  return View();
  </code></pre>
  
  <p><em>Stack trace</em></p>
  
  <blockquote>
    <p>[OutOfMemoryException: Exception of type 'System.OutOfMemoryException'
    was thrown.]    System.Text.StringBuilder.ExpandByABlock(Int32
    minBlockCharCount) +163    System.Text.StringBuilder.Append(Char*
    value, Int32 valueCount) +82<br>
    System.Text.StringBuilder.AppendHelper(String value) +31<br>
    System.Text.StringBuilder.Append(String value) +186<br>
    System.IO.StringWriter.Write(String value) +30<br>
    System.Web.WebPages.WebPageBase.Write(Object value) +87</p>
  </blockquote>