0

Simple as that: In ASP.NET MVC5 view, how do I pass parameter to requirejs urlArgs? I would like to read assembly version like this...

var assemblyVersion = System.Reflection.Assembly.GetExecutingAssembly()
                                                .GetName()
                                                .Version
                                                .ToString();

... and pass it to requirejs to bust cache and load the latest version. Tried various things but still unable to properly reach the requirejs configuration from the Razor markup :(

2 Answers 2

1

you can keep a hidden input element in cshtml and set it's value using

@System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

then in js

require.config({
    urlArgs: "bust=" + document.getElementById('yourinputelementid').value
});
Sign up to request clarification or add additional context in comments.

1 Comment

Ha, turns out I was retarded enough to assume there is nothing in the DOM when require.config() executes :D This is a correct answer. And I found another (preferred) solution to avoid stuffing the dom with the metadata such as version number...
0

Another solution I found:

example.cshtml

@{
  var assemblyVersion = typeof(SimpleMessages.Web.MvcApplication).Assembly
                                                                 .GetName()
                                                                 .Version
                                                                 .ToString();
}

@section scripts {
  <script>
      require.config({ urlArgs: "v=@assemblyVersion" });
      @Html.RequireJs("/Scripts/main.js", "/Scripts/My/chat-ko.js");
  </script>
}

This way there is nothing in the DOM, and assembly version is dynamically properly created.

HTH

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.