Your code should work fine as long as you have the jQuery.js file in that location.
Also you need to make sure that you called the UseStaticFiles()
method inside the Configure()
method(inside Startup.cs)
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
//Other configuration goes here
app.UseStaticFiles(); // This enables static file serving from the app.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
UseStaticFiles()
extension method enables static file serving including js files,css files etc..
You may consider using the environment
tag helpers to include script to your page for different configurations/enviornments.
It is not necessary that you should use the environment tag helper. You can directly put your script tags in the layout file. But the environment helpers allows us to conditionally render scripts based on the environment. (Minified-Bundled version vs All Un minified version)
<environment names="Development">
<script src="~/lib/jquery/dist/jquery.js"></script>
</environment>
<environment names="Staging,Production">
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery">
</script>
</environment>
If you want to include your custom scripts this way, take a look at this answer