how to use scripts in razor pages?

mc 5,426 Reputation points
2023-02-11T15:05:41.7033333+00:00

I create a js file in /Pages/Order/Index.cshtml.js

how to use it in /Pages/Order/Index.cshtml

<script src="/Order/Index.cshtml"></script> can not use it.

Developer technologies ASP.NET ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2023-02-11T15:35:41.51+00:00

    In Razor Pages, the JavaScript files belong in the wwwroot folder. The src path is relative to the wwwroot. See the Static File Service.

    You can also, use the @Section scripts {} to add JavaScript to a Razor Page as illustrated in the official documentation.

    Layout in ASP.NET Core

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.