Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I Return a Partial view depending on Controller within current page
    primarykey
    data
    text
    <p><strong>How do I render a partial view depending on the controller?</strong></p> <p>So..I need to render a partial view depending on the values that have been posted:</p> <pre><code> &lt;script type="text/javascript" language="javascript"&gt; $(document).ready(function () { $("#GetReport").click(function () { $("form[name=StatsForm]").submit(); }); }); &lt;/script&gt; &lt;% Html.RenderPartial("InterStats"); %&gt; //this is wrong i need it to render the partial depending on selection and only after the $("#GetReport").click </code></pre> <p>Controller:</p> <pre><code> /// &lt;summary&gt; /// POST /Stats/Index /// &lt;/summary&gt; /// &lt;param name="form"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; [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(); } /// &lt;/summary&gt; /// &lt;returns&gt;&lt;/returns&gt; /// [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&lt;InterRecord&gt;(); // a list of my anonymous type without the relationships interReportJson.InterRecordList = new List&lt;InterRecord&gt;(); 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 &amp;&amp; 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); } </code></pre> <p>At the moment without the &lt;% Html.RenderPartial("InterStats"); %> my partial is opening in a new window and with it its failing as there is no data untill after the form has been submitted. and also It might not be partial "InterStats" it could be partial "LeadsStats"</p> <p><strong>Edit</strong></p> <p>I was doing the following with AJAX:</p> <pre><code> &lt;script type="text/javascript"&gt; $("#GetReport").click(function () { var manufacturerId = $("#manufacturerId &gt; option:selected").attr("value"); var countryId = $("#countryId &gt; 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 &lt; data.length; i++) { var item1 = data[i]; //only display on graph if not 0 if (item1.Impressions &gt; 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 &amp;&amp; Highcharts.theme.textColor) || 'gray' } } }, legend: { align: 'right', x: -100, verticalAlign: 'top', y: 20, floating: true, backgroundColor: (Highcharts.theme &amp;&amp; Highcharts.theme.legendBackgroundColorSolid) || 'white', borderColor: '#CCC', borderWidth: 1, shadow: false }, tooltip: { formatter: function () { return '&lt;b&gt;' + this.x + '&lt;/b&gt;&lt;br/&gt;' + this.series.name + ': ' + this.y + '&lt;br/&gt;'; } }, plotOptions: { bar: { dataLabels: { enabled: true } } }, series: [{ name: 'Impressions', data: impressionsArray }, { name: 'Interactions', data: intsArray }] }); var table = document.getElementById("usertable"); var tabledata = ""; tabledata += "&lt;tr&gt;"; tabledata += "&lt;th&gt;Widget Name&lt;/th&gt;"; tabledata += "&lt;th&gt;Impressions&lt;/th&gt;"; tabledata += "&lt;th&gt;Interactions&lt;/th&gt;"; tabledata += "&lt;th&gt;CTR&lt;/th&gt;"; tabledata += "&lt;/tr&gt;"; for (var i = 0; i &lt; data.length; i++) { var item = data[i]; tabledata += "&lt;tr&gt;"; tabledata += "&lt;td&gt;" + item.WidgetName + "&lt;/td&gt;"; tabledata += "&lt;td&gt;" + item.Impressions + "&lt;/td&gt;"; tabledata += "&lt;td&gt;" + item.Interactions + "&lt;/td&gt;"; tabledata += "&lt;td&gt;" + item.Ctr.toFixed(2) + "%&lt;/td&gt;"; tabledata += "&lt;/tr&gt;"; } table.innerHTML = tabledata; $("th").css("background-color", "#3399FF"); $("tr:even").css("background-color", "#eeeeee"); $("tr:odd").css("background-color", "#ffffff"); } } ); }); &lt;/script&gt; </code></pre> <p>But this only work for one of the report as the format of the table/chrt varies depending on the report so i nned to seperate how to display them depending on the report id.</p> <p>I hope it is clear what I need to do please ask if not.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload