Home > database >  C# Razor, repeated Partial pages in a web page use the same data instead of haveing their own data
C# Razor, repeated Partial pages in a web page use the same data instead of haveing their own data

Time:02-01

I have a web page in which I want to display the same partial windrose chart 2 times with 2 different sets of data. However whatever data is returned for the 1st partial page is incorrectly used for the second partial page.

            <div >
            @{
                var YAxis = Model.GetWindroseReadings(0);
                var ChartName = "Chart1Hour";
                await Html.RenderPartialAsync("Charts/Partial/ChartWindroseVariable", new { YAxis, ChartName });
            }
        </div>
        <div >
            @{
                YAxis = Model.GetWindroseReadings(1);
                ChartName = "Chart24Hour";
                await Html.RenderPartialAsync("Charts/Partial/ChartWindroseVariable", new { YAxis, ChartName });
            }
        </div>

YAxis is an html string. How can I achieve this? Thanks for your help.

CodePudding user response:

You're rendering async but passing object that is the same object and changing its data. Don't re-use the object like that.

<div >
            @{
                var YAxis1 = Model.GetWindroseReadings(0);
                var ChartName1 = "Chart1Hour";
                await Html.RenderPartialAsync("Charts/Partial/ChartWindroseVariable", new { YAxis1, ChartName1 });
            }
        </div>
        <div >
            @{
                var YAxis2 = Model.GetWindroseReadings(1);
                var ChartName2 = "Chart24Hour";
                await Html.RenderPartialAsync("Charts/Partial/ChartWindroseVariable", new { YAxis2, ChartName2 });
            }
        </div>

CodePudding user response:

I am using:

            <div >
            @{
                var yAxis0 = Model.GetWindroseReadings(0);
                var ChartName = "Chart1Hour";
                await Html.RenderPartialAsync("Charts/Partial/ChartWindroseVariable", new { YAxis = yAxis0, ChartName });
            }
        </div>
        <div >
            @{
                await Task.Delay(1000);
                var yAxis1 = Model.GetWindroseReadings(1);
                ChartName = "Chart24Hour";
                await Html.RenderPartialAsync("Charts/Partial/ChartWindroseVariable", new { YAxis = yAxis1, ChartName });
            }
        </div>

Looking at the web page source I am correctly getting different strings of data for each of the partial views, so now my problem seems to be with HighCharts rendering.

Thank you for your help, I'll now go and look at the web page rendering.

  • Related