开发者

RazorView chart control

I'm converting from aspx view to razor. In the view I have the following code:

(i'm using dundas charts)

..
    var chart = new System.Web.UI.DataVisualization.Charting.Chart();
    chart.Width = 492;
    chart.Height = 406;
    chart.RenderType = RenderType.ImageTag;
    chart.Im开发者_如何学编程ageLocation = System.Configuration.ConfigurationManager.AppSettings["Temp"] + "/TempImagesChartPic_#SEQ(200,30)";
...
    ...
        // Render chart control
        chart.Page = (Page)this;
        var writer = new HtmlTextWriter(Page.Response.Output);
        chart.RenderControl(writer);

this worked fine in aspx however it throws "Cannot implicitly convert type 'System.Dynamic.DynamicObject' to 'System.Web.UI.Page'"

How do i make it work in razor view? thanks


I believe your problem lies with the line:

chart.Page = (Page)this;

Since in the Razor view 'this' is a dynamic object which can contain view data for use in the html.

You may try referencing like this and also remove Page. from the next line too and access response directly :

chart.Page = (Page) PageContext.Page;
var writer = new HtmlTextWriter(Response.Output);
chart.RenderControl(writer);


The Chart control that you are trying to use is a server side control which relies heavily on the ASP.NET WebForms infrastructure. The fact that you can use it in an ASP.NET MVC application (WebForms view engine) is only because of the heritage that this view engine has on classic WebForms. For charting in ASP.NET MVC applications (all view engines including Razor) I would recommend you using the System.Web.Helpers.Chart helper.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜