admin管理员组文章数量:1400115
I'm trying to change the layout page based on a cookie so i tried doing this:
function LoggedOrNot()
{
@if (Page.User.Identity.IsAuthenticated)
{
var x = document.cookie;
document.getElementByID("signupbutton").innerHTML = x;
}
}
but it's not recognizing document
I'm trying to change the layout page based on a cookie so i tried doing this:
function LoggedOrNot()
{
@if (Page.User.Identity.IsAuthenticated)
{
var x = document.cookie;
document.getElementByID("signupbutton").innerHTML = x;
}
}
but it's not recognizing document
2 Answers
Reset to default 7That's because Razor thinks you're still writing C# code. Use <text>
to tag it as plain text:
function LoggedOrNot()
{
@if (Page.User.Identity.IsAuthenticated)
{
<text>var x = document.cookie;
document.getElementByID("signupbutton").innerHTML = x;</text>
}
}
You should wrap it in text tags.
<text>var x = document.cookie; document.getElementByID("signupbutton").innerHTML = x</text>
This is because here you define a block of razor code and the ViewEngine, when try to execute the View see this like a c# mand. Apparently, in this context there isn't any variable called document. Furthermore, you need there to embed some js code. The way to do so, is to wrap it into text tags.
@if (Page.User.Identity.IsAuthenticated)
{
<text>var x = document.cookie;
document.getElementByID("signupbutton").innerHTML = x</text>
}
本文标签:
版权声明:本文标题:javascript - The name "document" does not exist in the current context, in the layout page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744202468a2595030.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论