I have found a few questions relating to this, but generally there are many different answers and they all seem very messy and complex.
If that is what needs to be done, then ok i better sit down and tackle it.
I want to know what the simplest and most efficient way is to add content to your head from partial views.
Reason I need to do this is i need certain java script and jquery on each page and it differs from page to page. I donot just want to add them all in the _layout view.
You can do this with sections. For example: I have more than two view which each other has same _Layout.My Index action in Company Controller has a sections as follow:
and Display Action in Invoice controller has same sections but different css and js as follow:
and then you can use this section in _Layout but its required argument should be false. Look at:
On your _Layout.cshtml page (Or any other master page) Use following code on inside of
<head></head>
tag.On the page that you want special css,script or any other item, specify their refernces. e.g.,