I'm sure this question must have been asked and answered somewhere on StackOverflow, but I've searched and searched and it's eluding me. I'd be very grateful of any assistance the community might provide.
I have a form with which I'm quite happy, but I'd like to improve it with a touch of JavaScript. The JS isn't relevant to any other page of my app, so I don't want to add it to my _Layout page.
Within the head element of my _Layout.cshtml page I have:
@RenderSection("head", required: false)
So, I need a line of code for my page (let's call it page.cshtml) that will add a block of JS (including script tags) into the head section of my eventual HTML. Essentially, I need to send a block of text to the RenderSection object, I think. Could someone tell me the correct syntax to put into my page.cshtml?
Why you need to add scripts specially to head section? MVC default
_Layout
page has@RenderSection("scripts", required: false)
section. So if you need to load scripts on your Viewpage.cshtml
(That uses_Layout
) you should place a code:When Razor render your page it will add this script to section.
Anyway if you want to add sctipt to this particulad head section it could be done same way: