0

I have an Identity Server 4 with an ASP.NET Core 3.1 MVC project and would like to add an external script into the _Layout.cshtml file. The JS file is being ran, however it is not working as expected. I believe this has to do with Identity Server 4 unable to parse the function or I am missing an ASP.NET Core MVC package.

Markup is supposed to be injected into the widget div via main.js script.

<body>
    <div id="widget"></div>
    <script src="~/js/[email protected]()"></script>
    @RenderSection("Scripts", required: false)
</body>

Note: The script works fine if I pull down this project https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/start-mvc?view=aspnetcore-8.0&tabs=visual-studio-code and insert the script into this _Layout.cshtml, I am able to see that it is working as expected.

The main difference being in .csproj - <TargetFramework>net6.0</TargetFramework> vs <TargetFramework>netcoreapp3.1</TargetFramework>

But I don't know if that matters. Please let me know if you need additional information.

2
  • Can you pls add how the script is rendered by opening devtools (F12) in the browser, go to the Elements inspector, and copying the rendered scripttag Commented Jan 7, 2024 at 21:45
  • 1
    This is how it's rendered in the elements tab - <script src="/js/main.js" type="text/javascript"></script> -- and when I right click on "/js/main.js" and select reveal in sources panel, it takes me to the source code of main.js, so it is coming back and being hit. @Pieterjan Commented Jan 7, 2024 at 21:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.