Javascript回调未在razor MVC中执行

Javascript回调未在razor MVC中执行,javascript,asp.net-mvc,html,dom,Javascript,Asp.net Mvc,Html,Dom,我有一个razor视图页面,如果我在系统的会话存储中有值,我想加载一些数据。我有以下cshtml <main class="admin-main" onreadystatechange="testMe"> <!--Hidden content here--> </main> 当我在chrome中运行它时,什么都没有发生,因为javascript从未执行过。我尝试过同时使用testMe和testMe(),但都没有效果 我甚至尝试将它包含在脚本标签和页面底部,但

我有一个razor视图页面,如果我在系统的会话存储中有值,我想加载一些数据。我有以下
cshtml

<main class="admin-main" onreadystatechange="testMe">
<!--Hidden content here-->
</main>
当我在chrome中运行它时,什么都没有发生,因为javascript从未执行过。我尝试过同时使用
testMe
testMe()
,但都没有效果

我甚至尝试将它包含在脚本标签和页面底部,但仍然没有响应。断点从不触发

是否有某种MVC方法可以做到这一点,我已经超越了?使用独立的html/css/js运行它很好。

根据,当文档的
readyState
属性发生更改时,会触发
readystatechange
事件。
main
标记没有
readyState
属性

如果希望在文档的
readyState
发生更改时运行该代码,可以像这样使用jQuery:

$(document).on('readystatechange', function() {
    if (document.readyState === 'loading') {
        console.log("Admin page accessed");
        if (sessionStorage.getItem('special')) {
            return;
        }
        else {
            window.location.href = "/Home/SpecialLogin";
        }
    }
}); 
$(document).on('readystatechange', function() {
    if (document.readyState === 'loading') {
        console.log("Admin page accessed");
        if (sessionStorage.getItem('special')) {
            return;
        }
        else {
            window.location.href = "/Home/SpecialLogin";
        }
    }
});