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.
@Html.Hidden("fileContent", fileContent);
<textarea style="display:none"> @fileContent </textarea>
None of the above works as the ways I expected and gives me,
Exception of type 'System.OutOfMemoryException' was thrown.
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.
Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
Yes, I agreed that's better to restructure the flow in another way (may be as Mediator suggest or have an action to return the JSON object.)
- Is that a limitation of MVC, the maximum size we can have for a MVC view?
- Is this because of the IIS Express configuration?
- Any other way to overcome this issue? Or the best way to pass a large object to the client browser.
Thank you for your time. Any help would be highly appreciated.
EDIT
Controller
var file = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/content/data.csv"));
ViewData.Add("file", file);
return View();
Stack trace
[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.] System.Text.StringBuilder.ExpandByABlock(Int32 minBlockCharCount) +163 System.Text.StringBuilder.Append(Char* value, Int32 valueCount) +82
System.Text.StringBuilder.AppendHelper(String value) +31
System.Text.StringBuilder.Append(String value) +186
System.IO.StringWriter.Write(String value) +30
System.Web.WebPages.WebPageBase.Write(Object value) +87