Lets say I have an helper:
@helper RenderCh开发者_StackOverflow社区art()
{
<div id="chart-content")" style="margin-top:15px;">
@*Draw Graph Here*@
@{
var key = new Chart(width: 60, height: 40)
.AddSeries(
chartType: "pie",
legend: "Rainfall",
xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May" },
yValues: new[] { "20", "20", "40", "10", "10" })
.Write();}
</div>
}
i am calling this helper in one of the my partials like that
@Helpers.RenderChart()
and then i am just getting only image in response and nothing else, just one image and no other content.
May be someone know how to fix it?
Looks like method .Write() writing image in response, but i need to generate just image.
You should render chart using separate action method and call this method with Url.Action inside some image source.
HomeController.cs
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Chart()
{
return View();
}
}
Chart.cshtml
@{
var basicChart = new Chart(width: 600, height: 400)
.AddTitle("Chart Title")
.AddSeries(
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
yValues: new[] { "2", "6", "4", "5", "3" })
.Write();
}
Index.cshtml
@{
ViewBag.Title = "Index";
}
<h2>
Index
</h2>
@RenderChart()
@helper RenderChart()
{
<div id="chart-content" style="margin-top: 15px">
<img src="@Url.Action("Chart")" alt="Chart is here"/>
</div>
}
You may take a look at the tutorials.
精彩评论