Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8823453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:21:34+00:00 2026-06-14T06:21:34+00:00

I was looking at the example here: http://tinyurl.com/au3vydl This example uses a helper to

  • 0

I was looking at the example here:

http://tinyurl.com/au3vydl

This example uses a helper to display a google graph image using razor:

@Html.DrawChart("p", "40,60,40", "250x100", "Pie Chart")

This method assembles the correct code to return the chart:

<img src='http://chart.apis.google.com/chart?chs=250x100&amp;chd=t:40,60,40&amp;cht=p&amp;chl=Pie Chart' />

However in the browser this displays as html code, not the actual image. If I copy the exact same code that the helper outputs into the view, it displays fine. Is there anything needed to change the output of the @Html.Helper to code instead of a literal string?

Helper code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Mvc;

namespace SolarCars.Helpers
{
    public static class GoogleChart
    {
        /// <summary>
        /// Draws the chart.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="chartType">Type of the chart.</param>
        /// <param name="chartData">The chart data.</param>
        /// <param name="chartSize">Size of the chart.</param>
        /// <param name="chartLabel">The chart label.</param>
        /// <returns></returns>
        public static string DrawChart(this HtmlHelper helper, string chartType, string chartData, string chartSize, string chartLabel)
        {
            StringBuilder chartHtml = new StringBuilder("<img src='http://chart.apis.google.com/chart?chs=");
            chartHtml.Append(chartSize);
            chartHtml.Append("&amp;chd=t:");
            chartHtml.Append(chartData);
            chartHtml.Append("&amp;cht=");
            chartHtml.Append(chartType);
            chartHtml.Append("&amp;chl=");
            chartHtml.Append(chartLabel);
            chartHtml.Append("' />");

            return chartHtml.ToString();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:21:35+00:00Added an answer on June 14, 2026 at 6:21 am

    If you return strings in an @ or <%: block the result will be automatically escaped. This was a (I think) a change between MVC1 and MVC2. The solution to this is to have your helper method return an instance of IHtmlString.

    public static IHtmlString DrawChart(...)
    

    Then switch your return to return a new HtmlString

    return new HtmlString(chartHtml.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking at an example on image upload with JQuery here: http://www.zurb.com/playground/ajax_upload Using this example
I was looking at an example at this link http://www.mkyong.com/spring-mvc/spring-mvc-form-handling-annotation-example/ Here the controller class
looking at this example of the jquery ui slider http://jqueryui.com/demos/slider/#steps i want to be
I've looking for an example for having Log scale, I've found something here: http://blog.dooapp.com/javafx-chart-api-and-logarithmic-scale-tag-ja
My full code is here: http://jsfiddle.net/HfNk9/13/ I am looking to this example jqueryUi autocomplete
I am looking at an example found here: http://perlmeme.org/tutorials/sort_function.html And it gives this code
I am trying to extend the JSON.net example given here http://james.newtonking.com/projects/json/help/CustomCreationConverter.html I have another
Looking at the example here - http://jsfiddle.net/uqYeQ/3/ The first row behaves as expected, returning
I'm using amcharts flash at the moment. see here: http://www.myinvestmentdecision.com.au/Sample-Results I want to change
I have been looking at the WF Wizard examples on endpoint.tv and here: http://stevenalexander.posterous.com/integrating-a-persisted-wf40-workflow-with-mv

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.