I wanted to fetch a key from appsettings.json file to javascript code in .net 8 MVC project.
i have added the key in appsetting.json in the below manner.
appsettings.json
{
"RequestCountlimit": "10"
}
Please let me know how to fetch the values from appsettings.json
2
Answers
If you want to get the appsetting.json value inside the js in MVC, you should firstly get it from the backend and then pass it to the view to get it.
More details, you could refer to below example:
View:
Result:
References : https://learn.microsoft.com/en-us/aspnet/core/mvc/views/dependency-injection?view=aspnetcore-8.0
You can use Dependency injection to get appsetting.json values in view.