3

I have a JQuery function FetchFunctions() that I need to run when the page is loaded. I am not sure how to do this within MVC using a template. I don't have a section on this page. Adding it to the _layout page doesn't make sense.

2 Answers 2

7

Inside of your page just add a script tag

somepage.cshtml

<script>
 window.onload = function(){
  //script goes here
 };
 //or if you prefer jQuery
 $(function(){
  //script goes here
 });
</script>
Sign up to request clarification or add additional context in comments.

Comments

2

Just include the following in your HTML:

<script>
    $(function () { FetchFunctions() });
</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.