asp.net mvc - Concatenate string in javascript -
i want dynamically append java script file name based on application culture name in mvc while giving reference of java script file.
for e.g.
<script src="~/clients/@tenant.clientname/backend/js/datetimepickerlocalizetion/fr.js"></script>
suppose culture fr
, want append dynamically in src
tag, file name fr.js
.
i have culture name in tenant
class, dependency injected.
but not able append file name .js
string.
so, how can achieve ?
you have couple of choices here. construct script link in code block , use in src
this:
@{ var scriptlink = $"~/clients/{tenant.clientname}/backend/js/datetimepickerlocalizetion/{tenant.culture}.js" } <script src="@scriptlink "></script>
if want keep 1 liner, have use braces mark code blocks in markup. this:
<script src="~/clients/@(tenant.clientname)/backend/js/datetimepickerlocalizetion/@(tenant.culture).js"></script>
Comments
Post a Comment