Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何根据当前页面中的控制器返回部分视图_C#_Jquery_Asp.net Mvc 3_Partial Views - Fatal编程技术网

C# 如何根据当前页面中的控制器返回部分视图

C# 如何根据当前页面中的控制器返回部分视图,c#,jquery,asp.net-mvc-3,partial-views,C#,Jquery,Asp.net Mvc 3,Partial Views,如何根据控制器渲染局部视图? 因此..我需要根据已发布的值渲染局部视图: <script type="text/javascript" language="javascript"> $(document).ready(function () { $("#GetReport").click(function () { $("form[name=Stat

如何根据控制器渲染局部视图?

因此..我需要根据已发布的值渲染局部视图:

  <script type="text/javascript" language="javascript">
      $(document).ready(function () {
                            $("#GetReport").click(function () {
                                $("form[name=StatsForm]").submit();

                            });
                        });
  </script>



<% Html.RenderPartial("InterStats"); %> //this is wrong i need it to render the partial depending on selection and only after the  $("#GetReport").click

$(文档).ready(函数(){
$(“#获取报告”)。单击(函数(){
$(“表单[name=StatsForm]”)。提交();
});
});
//这是错误的,我需要它根据选择渲染部分,并且仅在$(“#GetReport”)之后。单击
控制器:

 /// <summary>
        /// POST /Stats/Index
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(FormCollection form)
        {
            // Deal with the form 
            var manufacturerId = Convert.ToInt32(form["manufacturerId"]);
            var reportId = Convert.ToInt32(form["reportId"]);
            var categoryId = Convert.ToInt32(form["categoryId"]);
            var retailerId = Convert.ToInt32(form["retailerId"]);
            var countryId = Convert.ToInt32(form["countryId"]);
            var regionId = Convert.ToInt32(form["regionId"]);
            var manufacturerWidgetId = (form["ManufacturerWidgetId"]);
            var startDate = new DateTime(1, 1, 1, 0, 0, 0, 0);
            var endDate = new DateTime(1, 1, 1, 0, 0, 0, 0);    

            var reportName = _reportRepository.GetReport(reportId);


            switch (reportName.Code)
            {
                case "INTER":
                    return RedirectToAction("InterStats",
                                        new
                                        {
                                            manufacturerId = manufacturerId,
                                            countryId = countryId,
                                            startDate = "2013-01-01",
                                            endDate = "2013-01-31"

                                        });
                    break;
                case "CUMLEADS":
                    return RedirectToAction("LeadStats",
                                        new
                                        {
                                            manufacturerId = manufacturerId,
                                            countryId = countryId,
                                            categoryId = categoryId,
                                            startDate = startDate.ToString("yyyy-MM-dd"),
                                            endDate = endDate.ToString("yyyy-MM-dd")
                                        });
                    break;
                case "IMP":

                    break;
            }

            return View();


        }




    /// </summary>
    /// <returns></returns>
    /// [JsonpFilter]
    [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
    public ActionResult InterStats(int manufacturerId, int countryId, DateTime startDate, DateTime endDate)
    {

        //Get all manufacturerwidgets for manufacturer
        var manufacturerWidget = _manufacturerWidgetsRepository.GetManufacturerWidgetByManufacturerAndCountry(manufacturerId, countryId);
        var interReportJson = new InterReportJson();
        var interRecordList = new List<InterRecord>(); // a list of my anonymous type without the relationships
        interReportJson.InterRecordList = new List<InterRecord>();
        var count = 1;
        foreach (var mw in manufacturerWidget)
        {
            var widgetName = mw.Description;

            //Get the product stats data
            var imps = _productStatsRepository.GetSumImpressionsProductStatsForManufacturerCountryDate(
                mw.Id, countryId, startDate, endDate);


            var clicks = _productStatsRepository.GetSumClicksProductStatsForManufacturerCountryDate(
                mw.Id, countryId, startDate, endDate);

            float ctr = 0;
            if (imps != 0 && clicks != 0)
            {
                ctr = ((clicks / (float)imps) * 100);
            }



            //  Create the data for the report
            var interRecord = new InterRecord
            {
                WidgetName = widgetName,
                Impressions = imps,
                Interactions = clicks,
                Ctr = ctr,
                Count = count
            };




           interReportJson.InterRecordList.Add(interRecord);

            count++;
        }

        interReportJson.Counter = count;




        return PartialView(interReportJson);
    }
//
///职位/统计/索引
/// 
/// 
/// 
[接受动词(HttpVerbs.Post)]
公共行动结果索引(FormCollection表单)
{
//处理表格
var-manufacturerId=Convert.ToInt32(格式[“manufacturerId”]);
var reportId=Convert.ToInt32(格式[“reportId”]);
var categoryId=Convert.ToInt32(形式为[“categoryId”);
var retailerId=Convert.ToInt32(格式[“retailerId”);
var countryId=Convert.ToInt32(格式[“countryId”]);
var regionId=Convert.ToInt32(格式[“regionId”);
var manufacturerWidgetId=(格式[“manufacturerWidgetId”]);
var startDate=新的日期时间(1,1,1,0,0,0);
var endDate=新的日期时间(1,1,1,0,0,0);
var reportName=\u reportRepository.GetReport(reportId);
开关(reportName.Code)
{
“国际”一案:
返回重定向到操作(“状态间”),
刚出现的
{
manufacturerId=manufacturerId,
countryId=countryId,
startDate=“2013-01-01”,
endDate=“2013-01-31”
});
打破
案例“CUMLEADS”:
返回重定向到操作(“LeadStats”,
刚出现的
{
manufacturerId=manufacturerId,
countryId=countryId,
categoryId=categoryId,
startDate=startDate.ToString(“yyyy-MM-dd”),
endDate=endDate.ToString(“yyyy-MM-dd”)
});
打破
案例“IMP”:
打破
}
返回视图();
}
/// 
/// 
///[JsonpFilter]
[接受动词(HttpVerbs.Get | HttpVerbs.Post)]
公共行动结果州际(int manufacturerId、int countryId、DateTime startDate、DateTime endDate)
{
//获取制造商的所有制造商Widget
var manufacturerWidget=\u manufacturerwidgetsrespository.GetManufacturerWidgetByManufacturerAndCountry(manufacturerId,countryId);
var interReportJson=新的interReportJson();
var interRecordList=new List();//没有关系的匿名类型的列表
interReportJson.InterRecordList=新列表();
var计数=1;
foreach(制造商Widget中的var mw)
{
var widgetName=mw.说明;
//获取产品统计数据
var imps=\u productStatsRepository.GetSumImpressionsProductStatsFormanFactoryCountryDate(
mw.Id、countryId、开始日期、结束日期);
var clicks=\u productStatsRepository.GetSumClicksProductStatsFormanFactoryCountryDate(
mw.Id、countryId、开始日期、结束日期);
浮点数ctr=0;
如果(imps!=0&&clicks!=0)
{
ctr=((点击/(浮动)冲击)*100);
}
//为报告创建数据
var interecord=新的interecord
{
WidgetName=WidgetName,
印象=小鬼,
互动=点击,
Ctr=Ctr,
计数=计数
};
interReportJson.InterRecordList.Add(interRecord);
计数++;
}
interReportJson.Counter=count;
返回PartialView(interReportJson);
}
目前没有我的部分是在一个新的窗口打开,它的失败,因为没有数据,直到表单提交后。而且它可能不是部分的“州际”它可能是部分的“领先国家”

编辑

我使用AJAX做了以下工作:

 <script type="text/javascript">

            $("#GetReport").click(function () {


                var manufacturerId = $("#manufacturerId > option:selected").attr("value");
                var countryId = $("#countryId > option:selected").attr("value");
                var startDate = $("#startDate").val();
                var endDate = $("#endDate").val();

                //var manufacturerId = 241;
                //var countryId = 230;
                //                 var startDate = '2013-01-01';
                //                 var endDate = '2013-01-31';

                var theUrl = "/ProductStats/Parameters/" + manufacturerId + "/" + countryId + "/" + startDate + "/" + endDate;

                alert(theUrl);

                $.ajax({
                    type: "POST",
                    //contentType: "application/json; charset=utf-8",
                    url: theUrl,
                    data: { 'manufacturerId': manufacturerId, 'countryId': countryId, 'startDate': startDate, 'endDate': endDate },
                    dataType: "json",
                    success: function (data) {


                        //see this http://stackoverflow.com/questions/11472947/how-to-format-my-json-data-for-stack-column-chart-in-highcharts


                        var widgetNameArray = [];

                        var impressionsArray = [];

                        var intsArray = [];

                        for (var i = 0; i < data.length; i++) {

                            var item1 = data[i];
                            //only display on graph if not 0
                            if (item1.Impressions > 0) {


                                var widgetCategories = item1.WidgetName;

                                //put into an array
                                widgetNameArray.push(widgetCategories);

                                var imps = item1.Impressions;

                                impressionsArray.push(imps);

                                var ints = item1.Interactions;
                                intsArray.push(ints);
                            }
                        }


                        // Create the chart
                        $('#container').highcharts({
                            chart: {
                                type: 'column'
                            },
                            title: {
                                text: 'Inter Chart ' + startDate + ' to ' + endDate
                            },
                            xAxis: {
                                categories: widgetNameArray,
                                labels: {
                                    rotation: -45,
                                    align: 'right',
                                    style: {
                                        fontSize: '13px',
                                        fontFamily: 'Verdana, sans-serif'
                                    }
                                }
                            },
                            yAxis: {
                                min: 0,
                                title: {
                                    text: 'Impressions/Interactions'
                                },
                                stackLabels: {
                                    enabled: false,
                                    style: {
                                        fontWeight: 'bold',
                                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                                    }
                                }
                            },
                            legend: {
                                align: 'right',
                                x: -100,
                                verticalAlign: 'top',
                                y: 20,
                                floating: true,
                                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
                                borderColor: '#CCC',
                                borderWidth: 1,
                                shadow: false
                            },
                            tooltip: {
                                formatter: function () {
                                    return '<b>' + this.x + '</b><br/>' +
                        this.series.name + ': ' + this.y + '<br/>';
                                }
                            },
                            plotOptions: {
                                bar: {
                                    dataLabels: {
                                        enabled: true
                                    }
                                }
                            },
                            series: [{
                                name: 'Impressions',
                                data: impressionsArray
                            }, {
                                name: 'Interactions',
                                data: intsArray
                            }]
                        });




                        var table = document.getElementById("usertable");
                        var tabledata = "";

                        tabledata += "<tr>";
                        tabledata += "<th>Widget Name</th>";
                        tabledata += "<th>Impressions</th>";
                        tabledata += "<th>Interactions</th>";
                        tabledata += "<th>CTR</th>";
                        tabledata += "</tr>";



                        for (var i = 0; i < data.length; i++) {

                            var item = data[i];

                            tabledata += "<tr>";
                            tabledata += "<td>" + item.WidgetName + "</td>";
                            tabledata += "<td>" + item.Impressions + "</td>";
                            tabledata += "<td>" + item.Interactions + "</td>";
                            tabledata += "<td>" + item.Ctr.toFixed(2) + "%</td>";
                            tabledata += "</tr>";

                        }


                        table.innerHTML = tabledata;

                        $("th").css("background-color", "#3399FF");
                        $("tr:even").css("background-color", "#eeeeee");
                        $("tr:odd").css("background-color", "#ffffff");


                    }
                }
                 );


            });

        </script>

$(“#获取报告”)。单击(函数(){
var-manufacturerId=$(“#manufacturerId>选项:选中”).attr(“值”);
var countryId=$(“#countryId>选项:选中”).attr(“值”);
var startDate=$(“#startDate”).val();
var endDate=$(“#endDate”).val();
//var manufacturerId=241;
//var countryId=230;
//var startDate='2013-01-01';
//var endDate='2013-01-31';
var theUrl=“/ProductStats/Parameters/”+manufacturerId+“/”+countryId+“/”+startDate+“/”+endDate;
警报(theUrl);
$.ajax({
类型:“POST”,
//contentType:“应用程序/json;字符集=utf-8”,
url:theUrl,
数据:{'manufacturerId':manufacturerId,'countryId':countryId,'startDate':startDate,'endDate':endDate},
数据类型:“json”,
成功:功能(数据){
//看到这个了吗http://stackoverf
<div id="reportDiv">
   <!-- dynamic content will be populated here after user makes some selection, etc.. -->
</div>

<script type="text/javascript">
   $(document).ready(function () {
      $("#GetReport").click(function () {
         if (selectionDictatesThatReportBeShown) {
            // Make AJAX call and put response html in the reportDiv
            $('#reportDiv').load('/SomeController/SomeAction?key1=value1&key2=value2');
         }

         // optionally do this?
         $("form[name=StatsForm]").submit();
      });
   });
</script>
<script type="text/javascript">
        //<![CDATA[

     $(function () {

         $("#selectReport").hide();
         var manufacturerId;

         $("select#manufacturerId").change(function () {
             manufacturerId = $("#manufacturerId > option:selected").attr("value");
             $("#selectReport").show();

         });


         $("select#reportId").change(function () {
             var reportId = $("#reportId > option:selected").attr("value");

             var theUrl = "/ReportStats/GetReport/" + reportId + "/" + manufacturerId;

             $.ajax({
                 url: theUrl,
                 success: function (data) {
                     $('#ajaxOptionalFields').html(data);
                 },
                 error: function () {
                     alert("an error occured here");
                 }
             });
         });
     });

        //]]>
    </script>
 switch (report.Code)
            {
                case "INTER":
                    ViewData["InterStats"] = true;
                    break;
                case "CUMLEADS":
                    ViewData["CumLeadsStats"] = true;
                    break;
            }
<% if (Convert.ToBoolean(ViewData["InterStats"]))
   { %>
<% Html.RenderPartial("InterReport"); %>
<% }
   else if (Convert.ToBoolean(ViewData["CumLeadsStats"]))
   { %>
<% Html.RenderPartial("CummulativeReport"); %>
<% }  %>