Answered by:
How to specify the address of a json file in a script in the view

Question
-
User-259252065 posted
I'm implementing asp.net core 3.1 project and have a script like the following and I now in the URL, I'm reading a json file from a an address but I downloaded the json file and put it into my project (wwwroot_>JS files) and I want the URL to read from that file. But I don't know how to specify the address of my json file which is lying in src="~/js/Persian.json" in my project.
<script language="JavaScript" type="text/javascript" src="~/js/datatables.min.js"></script> <script> jQuery(document).ready(function ($) { $("#myDummyTable").DataTable({ //"searching": false, "language": { "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Persian.json" } }); }); </script>
Wednesday, August 19, 2020 4:58 AM
Answers
-
User711641945 posted
Hi Elenorarez,
It could work well in my project.Please check your static file location should be like below:
And share your whole razor view code would be better.Be sure your datatable has been applied successfully.
Best Regards,
Rena
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 20, 2020 9:25 AM
All replies
-
User711641945 posted
Hi Elenorarez,
Be sure your json file locates in wwwroot/js/Persian.json.
And be sure you have added the following middelware:
app.UseStaticFiles();
Then change your url like below:
$('#myDummyTable').DataTable({ "language": { "url": "js/Persian.json" } });
Best Regards,
Rena
Wednesday, August 19, 2020 8:27 AM -
User-259252065 posted
Thank you for your reply. I did as you mentioned but still the Datatable reads english characters.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseSession(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
<script language="JavaScript" type="text/javascript" src="~/js/datatables.min.js"></script><script>jQuery(document).ready(function ($) {$("#myDummyTable").DataTable({//"searching": false,"language": {//"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Persian.json""url":"js/Persian.json"}});});$('#request_layout').css({"background-color":"rgb(50, 149, 155)"});</script>Wednesday, August 19, 2020 9:10 AM -
User711641945 posted
Hi Elenorarez,
It could work well in my project.Please check your static file location should be like below:
And share your whole razor view code would be better.Be sure your datatable has been applied successfully.
Best Regards,
Rena
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 20, 2020 9:25 AM