title: Render fusionchart with Mvc3 and Razor engine
body: <p>Since yesterday, I try to run a sample of code to display a chart with FusionCharts and Mvc3 Razor and nothing works. Please.... help!!! :)</p>
  
  <p>Here is what I have done:</p>
  
  <ol>
  <li><p>I took the projet from Libero. <a href="http://liberofusioncharts.codeplex.com/" rel="nofollow">here</a></p></li>
  <li><p>After that, I used the project convertor <a href="http://aspnet.codeplex.com/releases/view/59008" rel="nofollow">here</a> to upgrade the project from Mvc2 to Mvc3.</p></li>
  <li><p>When I try to run to code (F5 and show the result in browser), that works fine; all graphics are displayed correctly.</p></li>
  </ol>
  
  <p>If I just create a new view with razor (.cshtml) instead of the current .aspx (replacing a view from the old syntax to the new razor) and I try to displayed the same graphic, the page is displayed correctly but without graphic. When I look into the page source with firebug or any other tools, no code is behind the scene. I also don't have any errors while looking with the Web Developer tool in Firefox.</p>
  
  <p>I just tried to add a Html.Raw in front of the code that generate the javascript to not encode the output and I have the same result. Also trying with returning HtmlString but again same result; no graphic is displayed.</p>
  
  <p>The key to don't miss in this problem is that if I try the exact same code but with an .aspx file, all is correct.</p>
  
  <p>In .aspx, the code looks like this:</p>
  
  <pre><code>&lt;%=Html.FChart("Chart01", ViewData["MyChart"], 600, 400)%&gt;
  </code></pre>
  
  <p>And in .cshtml:</p>
  
  <pre><code>@{Html.FChart("Chart01", ViewData["MyChart"], 600, 400); }
  </code></pre>
  
  <p>And finally, the html helper to generate this bunch of code:</p>
  
  <pre><code>  private static string RenderChart(string controlId, string xmlData, FusionChartBase chart, int width, int height)
    {
       String sControlId = controlId;
       String sJsVarId = "_lib_JS_" + controlId;
       String sDivId = "_lib_DIV_" + controlId;
       String sObjId = "_lib_OBJ_" + controlId;
       String sWidth = width.ToString();
       String sHeight = height.ToString();
  
       StringBuilder oBuilder = new StringBuilder();
  
       oBuilder.AppendLine(@"&lt;div id=""" + sDivId + @""" align=""center""&gt;&lt;/div&gt;");
  
       oBuilder.AppendLine(@"&lt;script type=""text/javascript""&gt;");
  
       oBuilder.AppendLine(@"var " + sControlId + @" = (function() {");
       oBuilder.AppendLine(@"    return {");
       oBuilder.AppendLine(@"        containerId: '" + sDivId + "',");
       oBuilder.AppendLine(@"        xmlData: '',");
       oBuilder.AppendLine(@"        chartType: '',");
       oBuilder.AppendLine(@"        showChart: function() {");
       oBuilder.AppendLine();
       oBuilder.AppendFormat(@"          var chartURL = '{0}' + this.chartType.replace('Chart', '{1}');", UrlSWF, SufixSWF);
       oBuilder.AppendLine(@"            var " + sJsVarId + @" = new FusionCharts(chartURL, """ + sObjId + @""", """ + sWidth + @""", """ + sHeight + @""");");
       oBuilder.AppendLine(@"            " + sJsVarId + @".setDataXML(this.xmlData);");
       oBuilder.AppendLine(@"            " + sJsVarId + @".render(""" + sDivId + @""");");
       oBuilder.AppendLine(@"        }");
       oBuilder.AppendLine(@"    }");
       oBuilder.AppendLine(@"})();");
  
       oBuilder.AppendLine(@"setTimeout(function(){");
       oBuilder.AppendLine(@"    " + sControlId + @".xmlData = """ + xmlData.Replace(@"""", @"'") + @""";");
       oBuilder.AppendLine(@"    " + sControlId + @".chartType = """ + chart.ChartType + @""";");
       oBuilder.AppendLine(@"    " + sControlId + @".showChart();");
       oBuilder.AppendLine(@"},0);");
  
       oBuilder.AppendLine(@"&lt;/script&gt;");
  
       return oBuilder.ToString();
    }
  </code></pre>
  
  <p>I don't know if I must set some configuration options in the web.config or what I don't understand in the behavior of Mvc2 compare to Mvc3, but it's very frustrating.</p>
  
  <p>If you have any idea, a big thanx in advance.</p>