MSajjadi
MSajjadi

Reputation: 3839

pageLoad in MVC

In ASP.NET I usually use pageLoad() JavaScript function, that gets executed every time the page sends a request even with Ajax (UpdatePanel).

Is there anything like that in Razor?

I mean a JavaScript function to get executed for every ajax request without using OnSuccess or something like that in AjaxOptions.

Upvotes: 0

Views: 2991

Answers (1)

JConstantine
JConstantine

Reputation: 3931

If you want a javascript function to run every time your page loads then you need to include the script you want at the top bottom of every page you want it to execute on

Then inside of that you'll have the js you want to run.

If you're using jquery then I suggest using $(document).ready()

Edit

Alternatively if you want some csharp/vb to run every time your page loads then you need to create a constructor in your controller and place the necessary code in there.

Upvotes: 4

Related Questions