我的页面包含以下html标记和内容。
<h1>A H1 title</h1>
<p>paragraph something...</p>
当我运行它时,页面按预期显示,带有h1标题和段落。但是当我在该页面上使用Razor标记包含新图表时,它会删除/覆盖标题和段落内容,并仅显示页面上的图表。共享布局也消失了。如何显示内容,布局和图表?
<h1>This is a h1 title</h1>
<p>Paragraph something...</p>
@{
var myChart = new Chart(width: 600, height: 400)
.AddTitle("Chart Title")
.AddSeries(
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
yValues: new[] { "2", "6", "4", "5", "3" })
.Write();
}
答案 0 :(得分:1)
您需要将图表代码放在单独的部分视图中,例如_Chart.cshtml
(仅包含@{ ..... }
之间的代码。然后在主视图中,使用<img>
元素进行显示图表
_Chart.cshtml
@{
var myChart = new Chart(width: 600, height: 400)
.AddTitle("Chart Title")
.AddSeries(
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
yValues: new[] { "2", "6", "4", "5", "3" })
.Write();
}
yourView.cshtml
<h1>This is a h1 title</h1>
<p>Paragraph something...</p>
<p><img src="_Chart.cshtml" /> </p>