我正在尝试在Bootstrap Modal popup
代码块中添加Html代码,如果它匹配某些条件,它将提醒用户。
这是我到目前为止所得到的,我收到错误@functions {}
这是抛出错误的代码片段。
CS0103: The name 'alert' does not exist in the current context
有没有办法在.cshtml
中的C#代码块中嵌入alert()这是此功能所在的整个代码
@functions{
void doSomething(){
if(ViewBag.token != null){
@alert("@ViewBag.token");
}
}
}
答案 0 :(得分:1)
功能完全是服务器端的。但是该脚本可以很容易地嵌入;如果您将其移动到您想要调用的页面,只需执行:
@if(ViewBag.token != null){
<script>
alert("@ViewBag.token");
</script>
}
如果令牌存在,这将被呈现。这不需要功能;这可能在@helper里面。