0

I want to dynamically append the 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 my culture is fr and I want to append it dynamically in src tag, so my file name will be like fr.js.

I already have the culture name in tenant class, for which dependency is already injected.

But I am not able to append the file name with .js string.

So, how can I achieve this ?

0

2 Answers 2

1

You have couple of choices here. You could construct script link in a code block and then use it in src like this:

@{
    var scriptLink = $"~/Clients/{tenant.ClientName}/Backend/js/DateTimepickerLocalizetion/{tenant.Culture}.js"
}

<script src="@scriptLink "></script>

If you want to keep it as 1 liner, you have to use braces to mark code blocks in markup. Like this:

<script src="~/Clients/@(tenant.ClientName)/Backend/js/DateTimepickerLocalizetion/@(tenant.Culture).js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome.. Thanks !
0

if you are using asp.net mvc, simply this will do the trick

<script src='@Scripts.Url(string.Format("~/Scripts/test.{0}.js", tenant.cultureName))'></script>

Comments

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.