简体   繁体   中英

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.

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:

Using sections in Editor/Display templates

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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