简体   繁体   English

在当前视图中渲染局部视图

[英]Render partial view in current view

I am trying to render a partial view, I am getting no errors or issues other than the graph just no displaying. 我正在尝试渲染局部视图,除了没有显示图形之外,没有其他错误或问题。

Main View 主视图

@{Html.RenderPartial("~/Views/Shared/Charts/LineChart.cshtml", Model);}

Partial View 部分视图

@model IEnumerable<VW_NewVulnerabilities>

<div class="chart">
    <canvas id="lineChart" style="height:250px"></canvas>
</div>
@section scripts {plenty of js in here }

All of this worked when it was in one view. 所有这些在一个视图中都有效。 Essentially i am trying to create a dynamic chartjs line chart so i can pass it a list of information and i can reuse it. 本质上,我正在尝试创建动态chartjs折线图,以便我可以将其传递给信息列表,并且可以重复使用。

You can not use section in partial view, by design, it is the responsibility of the view to set up all the require scripts, not partials. 您不能在局部视图中使用节,这是设计使然,视图的责任是设置所有需求脚本,而不是局部视图。

Having said that, if you want to set script in your partial view, you have to create something like helper to generate, such as this so answer: 话虽如此,如果您想在局部视图中设置脚本,则必须创建类似helper的东西来生成,例如:

Using sections in Editor/Display templates 使用编辑器/显示模板中的部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM