2013-05-09 111 views
0

好之前运行JavaScript,因此事情是这样的,如何服务器代码运行MVC2

我有一个观点至极呈现的图表(.NET图表),我想图表是大小相同网页浏览器窗口(浏览器将始终是IE 9)。

我尝试了几个例子,但没有为我工作。由于图表呈现为图像,因此我需要在图表呈现之前知道浏览器的大小(这发生在服务器端)。

我的意图是人们可以创建图表只需通过URL发送参数,使得来自另一个视图或控制器的值不是一个选项。

有没有办法做到这一点?这里是查看代码

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Charts.Master" Inherits="System.Web.Mvc.ViewPage<KpiDataBase.Models.ChartModel>" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
</asp:Content> 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 

<%if (Model.Series != null) 
{   
System.Web.UI.DataVisualization.Charting.Chart Chart1 = new System.Web.UI.DataVisualization.Charting.Chart(); 

Chart1.Width = 1400; -> this are the values that need to be dynamic 
Chart1.Height = 1100;-> this are the values that need to be dynamic 

... code for generating the chart.... 

// Render chart control 
Chart1.Page = this; 
HtmlTextWriter writer2 = new HtmlTextWriter(Page.Response.Output); 
Chart1.RenderControl(writer2);         
}%> 
</asp:Content> 

任何帮助将不胜感激。通过在互联网上搜索,我发现这只能通过JavaScript实现。如果可以运行这个脚本:

<script type="text/javascript"> 

    function getWidth() { 
     var width = $(window).width();} 
    return width, height ; 
</script> 

<script type="text/javascript"> 

    function getHeigth() { 
     var height = $(window).height();} 
    return height ; 
    </script> 

然后使用这些值来渲染我的图表,这将是伟大的。

回答

0

最后我用Ajax来执行此操作。

<script type="text/javascript"> 
$(document).ready(function() { 
    var width = screen.width; 
    var height = screen.height; 
    $.ajax({ 
     type: "GET", 
     url: "/Charts/Chart", 
     data: { 'width': width, 'height': height }, 
     success: function() { 
     } 
    }); 
}); 

相关问题