Respondida Equivalente <asp:Literal /> en MVC3 Razor

  • viernes, 04 de mayo de 2012 16:45
     
     

    Buen día a tod@s,

    Especificaciones: Visual Studio 2010 Framework 4.0

    Lisa y llanamente necesito saber si existe en MVC3 con el ViewEngine Razor un equivalente al control <asp:Literal />

    de ante mano muchas gracias,

    Gustavo Mondaca.

Todas las respuestas

  • viernes, 04 de mayo de 2012 17:04
     
     

    Hola Gustavo,

    Es tan sencillo y tan claro como tu pregunta, escribe esto en una vista y ves el resultado.

    "Esto es igual al control <strong>literal</strong>" revisa si quieres también esto.

    @Html.Encode y <text></text>.

    Saludos


    phurtado
    Mi Blog Blog
    Sigueme en Twitter

  • viernes, 04 de mayo de 2012 18:43
     
      Tiene código

    Hola Pedro,

    Gracias por tu respuesta pero el @Html.Encode no me sirve ya que actúa de la misma forma que despliege un ViewData["Message"] directamente, lo que sucede, es que en mi Controller tengo un método que me renderiza un gráfico y me devuelve código que debe ser interpretado antes del pintado en la Vista, con el Encode o directamente con el ViewData, me pinta el resultado, de esta forma en la Vista:

    "<div id='myNextDiv'><!-- START Code Block for Chart myNext -->\r\n<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"600\" height=\"300\" name=\"myNext\" id==\"myNext\" >\r\n<param name=\"allowScriptAccess\" value=\"always\" />\r\n<param name=\"movie\" value=\"../FusionCharts/Column3D.swf\"/>\r\n<param name=\"FlashVars\" value=\"&chartWidth=600&chartHeight=300&debugMode=0&registerWithJS=0&DOMId=myNext&dataXML=<chart caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' showValues='0' formatNumberScale='0' showBorder='1'><set label='Jan' value='462' /><set label='Feb' value='857' /><set label='Mar' value='671' /><set label='Apr' value='494' /><set label='May' value='761' /><set label='Jun' value='960' /><set label='Jul' value='629' /><set label='Aug' value='622' /><set label='Sep' value='376' /><set label='Oct' value='494' /><set label='Nov' value='761' /><set label='Dec' value='960' /></chart>\" />\r\n<param name=\"quality\" value=\"high\" />\r\n<embed src=\"../FusionCharts/Column3D.swf\" FlashVars=\"&chartWidth=600&chartHeight=300&debugMode=0&registerWithJS=0&DOMId=myNext&dataXML=<chart caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' showValues='0' formatNumberScale='0' showBorder='1'><set label='Jan' value='462' /><set label='Feb' value='857' /><set label='Mar' value='671' /><set label='Apr' value='494' /><set label='May' value='761' /><set label='Jun' value='960' /><set label='Jul' value='629' /><set label='Aug' value='622' /><set label='Sep' value='376' /><set label='Oct' value='494' /><set label='Nov' value='761' /><set label='Dec' value='960' /></chart>\" quality=\"high\" width=\"600\" height=\"300\" name=\"myNext\" id=\"myNext\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"  />\r\n</object>\r\n<!-- END Code Block for Chart myNext -->\r\n</div>"

    lo que necesito es que sea interpretado antes del pintado.

    nuevamente muchas gracias.

  • viernes, 04 de mayo de 2012 18:55
     
      Tiene código

    Hola Gustavo,

    Perdona pero puedes hacerlo con @Html.Raw, pero cuidadin con la seguridad:)

    @Html.Raw("Esto es igual al control <strong>literal</strong>")

    Saludos,


    phurtado
    Mi Blog Blog
    Sigueme en Twitter

  • viernes, 04 de mayo de 2012 19:22
     
     

    Definitivamente no me funciona Pedro, ahora no pinta en la vista el código (no interpretado) pero al parecer no lo interpreta, como resultado debería tener un gráfico en Flash (FusionCharts) pero el resultado aplicando el @Html.Raw es absolutamente nada en la Vista.

    Saludos


  • viernes, 04 de mayo de 2012 20:22
     
     

    Hola Gustavo,

    Nos puedes pasar el código de la vista y del controlador y de esa forma te podemos ayudar seguro.

    Piensa una cosa si Raw no funciona y HtlEncode no funciona no piensas por un momento que el error está en otro sitio, piensa:)

    Saludos,


    phurtado
    Mi Blog Blog
    Sigueme en Twitter

  • viernes, 04 de mayo de 2012 21:05
     
      Tiene código

    Estimado Pedro,

    Mi View:

    @{
        ViewBag.Title = "Index";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    <h2>Index</h2>
    
    <div id="chartContainer">FusionCharts will load here!</div>          
       
    @{
        string grafico = ViewData["Message"] as string;
    }
    
    <br /><br />
    -> Titulo Grafico
    <br />
    @grafico
    <br /><br />
    -> Titulo Encode
    <br />
    @Html.Encode(ViewData["Message"])
    <br /><br />
    -> Titulo Raw
    <br />
    @Html.Raw(grafico.ToString())

    Mi Controller:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using InfoSoftGlobal;
    using System.Text;
    
    namespace FSCSManual.Controllers
    {
        public class HomeController : Controller
        {
            //
            // GET: /Home/
    
            public ActionResult Index()
            {
                StringBuilder xmlData = new StringBuilder();
                xmlData.Append("<chart caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' showValues='0' formatNumberScale='0' showBorder='1'>");
                xmlData.Append("<set label='Jan' value='462' />");
                xmlData.Append("<set label='Feb' value='857' />");
                xmlData.Append("<set label='Mar' value='671' />");
                xmlData.Append("<set label='Apr' value='494' />");
                xmlData.Append("<set label='May' value='761' />");
                xmlData.Append("<set label='Jun' value='960' />");
                xmlData.Append("<set label='Jul' value='629' />");
                xmlData.Append("<set label='Aug' value='622' />");
                xmlData.Append("<set label='Sep' value='376' />");
                xmlData.Append("<set label='Oct' value='494' />");
                xmlData.Append("<set label='Nov' value='761' />");
                xmlData.Append("<set label='Dec' value='960' />");
                xmlData.Append("</chart>");
    
                //Create the chart - Column 3D Chart with data from xmlData variable using dataXML method
                FusionCharts fusionCharts = new FusionCharts();
    
                ViewData["Message"] = fusionCharts.RenderChartHTML("../FusionCharts/Column3D.swf", "", xmlData.ToString(), "myNext", "600", "300", false);
                return View();
            }
    
        }
    }

    Clase FusionCharts:

    using System;
    using System.Text;
    using System.Collections;
    using System.Web.UI.WebControls;
    
    namespace InfoSoftGlobal
    {
        /// <summary>
        /// Summary description for FusionCharts.
        /// </summary>
        public class FusionCharts
        {
            /// <summary>
            /// encodes the dataURL before it's served to FusionCharts
            /// If you have parameters in your dataURL, you'll necessarily need to encode it
            /// </summary>
            /// <param name="dataURL">dataURL to be fed to chart</param>
            /// <param name="noCacheStr">Whether to add aditional string to URL to disable caching of data</param>
            /// <returns>Encoded dataURL, ready to be consumed by FusionCharts</returns>
            public string EncodeDataURL(string dataURL, bool noCacheStr)
            {
                string result = dataURL;
                if (noCacheStr)
                {
                    result += (dataURL.IndexOf("?") != -1) ? "&" : "?";
                    //Replace : in time with _, as FusionCharts cannot handle : in URLs
                    result += "FCCurrTime=" + DateTime.Now.ToString().Replace(":", "_");
                }
    
                return System.Web.HttpUtility.UrlEncode(result);
            }
    
            /// <summary>
            /// Generate html code for rendering chart
            /// This function assumes that you've already included the FusionCharts JavaScript class in your page
            /// </summary>
            /// <param name="chartSWF">SWF File Name (and Path) of the chart which you intend to plot</param>
            /// <param name="strURL">If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)</param>
            /// <param name="strXML">If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)</param>
            /// <param name="chartId">Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.</param>
            /// <param name="chartWidth">Intended width for the chart (in pixels)</param>
            /// <param name="chartHeight">Intended height for the chart (in pixels)</param>
            /// <param name="debugMode">Whether to start the chart in debug mode</param>
            /// <param name="registerWithJS">Whether to ask chart to register itself with JavaScript</param>
            /// /// <param name="transparent">Whether transparent chart (true / false)</param>
            /// <returns>JavaScript + HTML code required to embed a chart</returns>
            private string RenderChartALL(string chartSWF, string strURL, string strXML, string chartId, string chartWidth, string chartHeight, bool debugMode, bool registerWithJS, bool transparent)
            {
    
                StringBuilder builder = new StringBuilder();
    
                builder.AppendFormat("<!-- START Script Block for Chart {0} -->" + Environment.NewLine, chartId);
                builder.AppendFormat("<div id='{0}Div' align='center'>" + Environment.NewLine, chartId);
                builder.Append("Chart." + Environment.NewLine);
                builder.Append("</div>" + Environment.NewLine);
                builder.Append("<script type=\"text/javascript\">" + Environment.NewLine);
                builder.AppendFormat("var chart_{0} = new FusionCharts(\"{1}\", \"{0}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\");" + Environment.NewLine, chartId, chartSWF, chartWidth, chartHeight, boolToNum(debugMode), boolToNum(registerWithJS));
                if (strXML.Length == 0)
                {
                    builder.AppendFormat("chart_{0}.setDataURL(\"{1}\");" + Environment.NewLine, chartId, strURL);
                }
                else
                {
                    builder.AppendFormat("chart_{0}.setDataXML(\"{1}\");" + Environment.NewLine, chartId, strXML);
                }
    
                if (transparent == true)
                {
                    builder.AppendFormat("chart_{0}.setTransparent({1});" + Environment.NewLine, chartId, "true");
                }
    
                builder.AppendFormat("chart_{0}.render(\"{1}Div\");" + Environment.NewLine, chartId, chartId);
                builder.Append("</script>" + Environment.NewLine);
                builder.AppendFormat("<!-- END Script Block for Chart {0} -->" + Environment.NewLine, chartId);
                return builder.ToString();
            }
    
            /// <summary>
            /// Generate html code for rendering chart
            /// This function assumes that you've already included the FusionCharts JavaScript class in your page
            /// </summary>
            /// <param name="chartSWF">SWF File Name (and Path) of the chart which you intend to plot</param>
            /// <param name="strURL">If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)</param>
            /// <param name="strXML">If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)</param>
            /// <param name="chartId">Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.</param>
            /// <param name="chartWidth">Intended width for the chart (in pixels)</param>
            /// <param name="chartHeight">Intended height for the chart (in pixels)</param>
            /// <param name="debugMode">Whether to start the chart in debug mode</param>
            /// <param name="registerWithJS">Whether to ask chart to register itself with JavaScript</param>
            /// <param name="transparent">Whether transparent chart (true / false)</param>
            /// <returns>JavaScript + HTML code required to embed a chart</returns>
            public string RenderChart(string chartSWF, string strURL, string strXML, string chartId, string chartWidth, string chartHeight, bool debugMode, bool registerWithJS, bool transparent)
            {
                return RenderChartALL(chartSWF, strURL, strXML, chartId, chartWidth, chartHeight, debugMode, registerWithJS, transparent);
            }
    
            /// <summary>
            /// Generate html code for rendering chart
            /// This function assumes that you've already included the FusionCharts JavaScript class in your page
            /// </summary>
            /// <param name="chartSWF">SWF File Name (and Path) of the chart which you intend to plot</param>
            /// <param name="strURL">If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)</param>
            /// <param name="strXML">If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)</param>
            /// <param name="chartId">Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.</param>
            /// <param name="chartWidth">Intended width for the chart (in pixels)</param>
            /// <param name="chartHeight">Intended height for the chart (in pixels)</param>
            /// <param name="debugMode">Whether to start the chart in debug mode</param>
            /// <param name="registerWithJS">Whether to ask chart to register itself with JavaScript</param>
            /// <returns>JavaScript + HTML code required to embed a chart</returns>
            public string RenderChart(string chartSWF, string strURL, string strXML, string chartId, string chartWidth, string chartHeight, bool debugMode, bool registerWithJS)
            {
                return RenderChart(chartSWF, strURL, strXML, chartId, chartWidth, chartHeight, debugMode, registerWithJS, false);
            }
    
            /// <summary>
            /// Renders the HTML code for the chart. This
            /// method does NOT embed the chart using JavaScript class. Instead, it uses
            /// direct HTML embedding. So, if you see the charts on IE 6 (or above), you'll
            /// see the "Click to activate..." message on the chart.
            /// </summary>
            /// <param name="chartSWF">SWF File Name (and Path) of the chart which you intend to plot</param>
            /// <param name="strURL">If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)</param>
            /// <param name="strXML">If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)</param>
            /// <param name="chartId">Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.</param>
            /// <param name="chartWidth">Intended width for the chart (in pixels)</param>
            /// <param name="chartHeight">Intended height for the chart (in pixels)</param>
            /// <param name="debugMode">Whether to start the chart in debug mode</param>
            /// <returns></returns>
    
            public string RenderChartHTML(string chartSWF, string strURL, string strXML, string chartId, string chartWidth, string chartHeight, bool debugMode)
            {
                return RenderChartHTMLALL(chartSWF, strURL, strXML, chartId, chartWidth, chartHeight, debugMode, false, false);
            }
    
            /// <summary>
            /// Renders the HTML code for the chart. This
            /// method does NOT embed the chart using JavaScript class. Instead, it uses
            /// direct HTML embedding. So, if you see the charts on IE 6 (or above), you'll
            /// see the "Click to activate..." message on the chart.
            /// </summary>
            /// <param name="chartSWF">SWF File Name (and Path) of the chart which you intend to plot</param>
            /// <param name="strURL">If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)</param>
            /// <param name="strXML">If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)</param>
            /// <param name="chartId">Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.</param>
            /// <param name="chartWidth">Intended width for the chart (in pixels)</param>
            /// <param name="chartHeight">Intended height for the chart (in pixels)</param>
            /// <param name="debugMode">Whether to start the chart in debug mode</param>
            /// <param name="registerWithJS">Whether to ask chart to register itself with JavaScript</param>
            /// <returns></returns>
    
            public string RenderChartHTML(string chartSWF, string strURL, string strXML, string chartId, string chartWidth, string chartHeight, bool debugMode, bool registerWithJS)
            {
                return RenderChartHTMLALL(chartSWF, strURL, strXML, chartId, chartWidth, chartHeight, debugMode, registerWithJS, false);
            }
    
            /// <summary>
            /// Renders the HTML code for the chart. This
            /// method does NOT embed the chart using JavaScript class. Instead, it uses
            /// direct HTML embedding. So, if you see the charts on IE 6 (or above), you'll
            /// see the "Click to activate..." message on the chart.
            /// </summary>
            /// <param name="chartSWF">SWF File Name (and Path) of the chart which you intend to plot</param>
            /// <param name="strURL">If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)</param>
            /// <param name="strXML">If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)</param>
            /// <param name="chartId">Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.</param>
            /// <param name="chartWidth">Intended width for the chart (in pixels)</param>
            /// <param name="chartHeight">Intended height for the chart (in pixels)</param>
            /// <param name="debugMode">Whether to start the chart in debug mode</param>
            /// <param name="registerWithJS">Whether to ask chart to register itself with JavaScript</param>
            /// <param name="transparent">Whether transparent chart (true / false)</param>
            /// <returns></returns>
            public string RenderChartHTML(string chartSWF, string strURL, string strXML, string chartId, string chartWidth, string chartHeight, bool debugMode, bool registerWithJS, bool transparent)
            {
                return RenderChartHTMLALL(chartSWF, strURL, strXML, chartId, chartWidth, chartHeight, debugMode, registerWithJS, transparent);
            }
    
            private string RenderChartHTMLALL(string chartSWF, string strURL, string strXML, string chartId, string chartWidth, string chartHeight, bool debugMode, bool registerWithJS, bool transparent)
            {
                //Generate the FlashVars string based on whether dataURL has been provided
                //or dataXML.
                StringBuilder strFlashVars = new StringBuilder();
                string flashVariables = String.Empty;
                if (strXML.Length == 0)
                {
                    //DataURL Mode
                    flashVariables = String.Format("&chartWidth={0}&chartHeight={1}&debugMode={2}&registerWithJS={3}&DOMId={4}&dataURL={5}", chartWidth, chartHeight, boolToNum(debugMode), (registerWithJS), chartId, strURL);
                }
                else
                //DataXML Mode
                {
                    flashVariables = String.Format("&chartWidth={0}&chartHeight={1}&debugMode={2}&registerWithJS={3}&DOMId={4}&dataXML={5}", chartWidth, chartHeight, boolToNum(debugMode), boolToNum(registerWithJS), chartId, strXML);
                }
    
                strFlashVars.AppendFormat("<!-- START Code Block for Chart {0} -->" + Environment.NewLine, chartId);
                strFlashVars.AppendFormat("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"{0}\" height=\"{1}\" name=\"{2}\" id==\"{2}\" >" + Environment.NewLine, chartWidth, chartHeight, chartId);
                strFlashVars.Append("<param name=\"allowScriptAccess\" value=\"always\" />" + Environment.NewLine);
                strFlashVars.AppendFormat("<param name=\"movie\" value=\"{0}\"/>" + Environment.NewLine, chartSWF);
                strFlashVars.AppendFormat("<param name=\"FlashVars\" value=\"{0}\" />" + Environment.NewLine, flashVariables);
                strFlashVars.Append("<param name=\"quality\" value=\"high\" />" + Environment.NewLine);
    
                string strwmode = "";
                if (transparent == true)
                {
                    strFlashVars.Append("<param name=\"wmode\" value=\"transparent\" />" + Environment.NewLine);
                    strwmode = "wmode=\"transparent\"";
                }
    
                strFlashVars.AppendFormat("<embed src=\"{0}\" FlashVars=\"{1}\" quality=\"high\" width=\"{2}\" height=\"{3}\" name=\"{4}\" id=\"{4}\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" {5} />" + Environment.NewLine, chartSWF, flashVariables, chartWidth, chartHeight, chartId, strwmode);
                strFlashVars.Append("</object>" + Environment.NewLine);
                strFlashVars.AppendFormat("<!-- END Code Block for Chart {0} -->" + Environment.NewLine, chartId);
                string FlashXML = "<div id='" + chartId + "Div'>"; FlashXML += strFlashVars.ToString() + "</div>";
                return FlashXML;
    
    
            }
    
            /// <summary>
            /// Transform the meaning of boolean value in integer value
            /// </summary>
            /// <param name="value">true/false value to be transformed</param>
            /// <returns>1 if the value is true, 0 if the value is false</returns>
            private int boolToNum(bool value)
            {
                return value ? 1 : 0;
            }
    
        }
    
    }
    

    Disculpa de todas formas estoy recién cambiando MVC2 a MVC3 con un ViewEngine distinto, aún no conozco todas las posibilidades como para poder descartar, si mis únicas 2 opciones son Encore y Raw podría haber dicho "claro el error está en otro lugar" pero no lo sé.

    Nuevamente muchas gracias por tu ayuda.

    Saludos,

    Gustavo Mondaca.

  • viernes, 04 de mayo de 2012 21:19
     
     

    Hola Gustavo,

    Déjame que duerma esta noche lo pruebo y mañana te contesto, que menudo marrón me acabas de meter:)

    Saludos y Disfruta.


    phurtado
    Mi Blog Blog
    Sigueme en Twitter

  • sábado, 05 de mayo de 2012 10:43
     
     Respondida Tiene código

    Hola Gustavo,

    El planteamiento que estás haciendo de esto creo que es incorrecto y posiblmente porque desconoces la posibilidad de trabajar con HtmlHelper.

    Mira como yo plantearía esto.

    1. Defino una clase chart y una clase Month que representa los valores de los meses.

    public class Chart
        {
            public string chartSWF{get;set;}
            public string strURL{get;set;}
            public string strXML{get;set;}
            public string chartId{get;set;}
            public string chartWidth{get;set;}
            public string chartHeight{get;set;}
            public bool debugMode{get;set;}
            public bool registerWithJS{get;set;}
            public bool transparent{get;set;}
        }
        public class Month
        {
            public string Label { get; set; }
            public int Value { get; set; }
            public static List<XElement> GetMonths(List<Month> Meses)
            {
                List<XElement> elements = new List<XElement>();
                foreach (var item in Meses)
                {
                    elements.Add(new XElement("set",
                            new XAttribute("label", item.Label), new XAttribute("Value", item.Value)));
                }
                return elements;
            }
        }


    Si te das cuenta utilizo Linq Xml para contruir los meses.

    2. Define un Helper

     public static class MisHelper
        {
            public static MvcHtmlString RenderChar(this System.Web.Mvc.HtmlHelper Helper,Chart Chart)
            {
                TagBuilder builder = new TagBuilder("div");
                builder.Attributes.Add("id", Chart.chartId);
                builder.Attributes.Add("align","center");
    
                    
                TagBuilder script = new TagBuilder("script");
                script.Attributes.Add("Type", "text/javascript");
    
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(builder.ToString(TagRenderMode.Normal));
                sb.AppendLine(script.ToString(TagRenderMode.Normal));
    
                return new MvcHtmlString(sb.ToString());
            }
        }


    Este solamente lo he dejado preparada para renderizar el div y el script el resto te lo dejo a ti:).

    3. En el Controlador haz lo siguiente.

    public ActionResult Index()
            {
                ViewBag.Message = "Welcome to ASP.NET MVC!";
    
                List<Month> Meses = new List<Month>()
                {
                    new Month(){Label="Jan",Value=462},
                    new Month(){Label="Feb",Value=857},
                    new Month(){Label="Mar",Value=671},
                    new Month(){Label="Apr",Value=494},
                    new Month(){Label="May",Value=761},
                    new Month(){Label="Jun",Value=960},
                    new Month(){Label="Jul",Value=629},
                    new Month(){Label="Aug",Value=622},
                    new Month(){Label="Sep",Value=376},
                    new Month(){Label="Oct",Value=494},
                    new Month(){Label="Nov",Value=761},
                    new Month(){Label="Dic",Value=960}
                };
    
                XElement XChar = new XElement("chart",
                    new XAttribute("caption","Monthly Unit Sales"),
                    new XAttribute("xAxisName","Month"),
                    new XAttribute("yAxisName","Units"),
                    new XAttribute("showValues","0"),
                    new XAttribute("formatNumberScale","0"),
                    new XAttribute("showBorder","1"),
                    Month.GetMonths(Meses)        
                    );
    
                Chart chart = new Chart()
                {
                    chartSWF = "../FusionCharts/Column3D.swf",
                    strURL = string.Empty,
                    strXML = XChar.ToString(),
                    chartId = "MiNext",
                    chartWidth = "600",
                    chartHeight = "300",
                    debugMode = false
                };
    
                ViewBag.Chart = chart;
    
              
    
                
    
                return View();
            }


    Y Por último en la vista esto.

    @using MvcApplication17;
    @{
        ViewBag.Title = "Home Page";
        MvcApplication17.Chart chart = ViewBag.Chart as MvcApplication17.Chart;
    }
    
    <h2>@ViewBag.Message</h2>
    <p>
    
    To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>
    Esto es igual al control <strong>literal</strong>
    <br />
    
    @Html.RenderChar(chart)
    


    El resultado final en Html es el siguiente.

    <div align="center" id="MiNext"></div>
    
    <script Type="text/javascript"></script> 

    También podrías utilizar esto.

    http://weblogs.asp.net/imranbaloch/archive/2011/03/21/chart-helper-in-asp-net-mvc-3-0-with-transparent-background.aspx

    Suerte y a terminarlo:)

    Saludos,


    phurtado
    Mi Blog Blog
    Sigueme en Twitter

    • Marcado como respuesta Gustavo Mondaca lunes, 07 de mayo de 2012 19:38
    •  
  • sábado, 05 de mayo de 2012 11:20
     
     Respondida Tiene código

    Hola Gustavo,

    Perdona que se me paso un tema las sentencias javascript tienes que asignarlas a la propiedad innerHtml del tagbuilder de esta forma.

    TagBuilder script = new TagBuilder("script");
                script.Attributes.Add("Type", "text/javascript");
                script.InnerHtml = "alert('Hola');";

    Y el resultado final será este.

    <div align="center" id="MiNext"></div>
    
    <script Type="text/javascript">alert('Hola');</script>

    Saludos,


    phurtado
    Mi Blog Blog
    Sigueme en Twitter

    • Marcado como respuesta Gustavo Mondaca lunes, 07 de mayo de 2012 19:38
    •  
  • lunes, 07 de mayo de 2012 19:39
     
     

    Muchas gracias Pedro, el tema se solucionó.