MVC 中的页面加载

发布于 2025-01-02 02:57:47 字数 223 浏览 2 评论 0原文

在 ASP.NET 中,我通常使用 pageLoad() JavaScript 函数,每次页面发送请求时都会执行该函数,即使使用 Ajax (UpdatePanel) 也是如此。

Razor 中有类似的东西吗?

我的意思是为每个 ajax 请求执行一个 JavaScript 函数,而不使用 OnSuccess 或 AjaxOptions 中类似的东西。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无尽的现实 2025-01-09 02:57:47

如果您希望每次加载页面时都运行一个 javascript 函数,那么您需要在您希望其执行的每个页面的 top 底部包含您想要的脚本,

然后在其中您将拥有你想要运行的js。

如果您使用 jquery 那么我建议使用 $(document).ready()

Edit

或者,如果您希望每次加载页面时运行一些 csharp/vb 那么您需要在您的控制器并在其中放置必要的代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文