What is the best way of adding external files from a partial view?
I need to do something like this
code in partial view:
@{
var files = new List<string>();
files.Add("some path");
files.Add("some path");
ViewBag.Files = files;
}
in layout page
@foreach (var file in ViewBag.Files) {
@file
}
this does not actually work though
As promised
You can’t render
@section‘s as it’s not supported when rendered by Partial Views, until then you can do this trick:in your
_Layout.cshtmlwriteThe first one is the default, the second line is your brand new way to render a section, I use both in my code…
Now let’s add some code to our Partial View
instead of
replace it with:
and our little helper that you just put inside your
Modelsfolder and reference it in your Partial View and Layout PageTo render CSS, all you need to so is using other section name, for example:
In
_Layout.cshtmlin your Partial Views
I hope this helps.