检查ViewBag值是在JavaScript present [英] Check ViewBag Value is present in javascript

查看:132
本文介绍了检查ViewBag值是在JavaScript present的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用剃刀模板,下面是场景

  $(函数(){
   //如果(ViewBag.IsCallFunction){
      somefunction();
   //
  //做别的事情
});

如果一个viewBag变量present,即不为空,如果它被设置为true,那么我想调用一些JavaScript函数。我该怎么做呢?


解决方案

  @ {如果(ViewBage.somevalue = NULL&放大器;!&安培; ViewBage.somevalue ==真)
  {
   <脚本类型=文/ JavaScript的>
   somefunction();
   < / SCRIPT>
  }
}

但请记住这将让称作渲染,按OP,你不能把它,你可以渲染它,所以当文档被装载调用它里面的document.ready

I am using razor template and following is the scenario

$(function(){
   //if (ViewBag.IsCallFunction){
      somefunction();
   //
  //do something else
});

If a viewBag variable is present, i.e. not null and if it is set to true, then I would like to call some javascript function. How do I do this?

解决方案

@{if(ViewBage.somevalue!=null && ViewBage.somevalue=="true")
  {
   <script type="text/javascript">
   somefunction();
   </script>
  }
}

but remember this will get called as rendered, as per OP, you can't call it, you can render it, so call it inside document.ready when document is loaded

这篇关于检查ViewBag值是在JavaScript present的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆