我可以viewbag值传递给jQuery的在MVC2 [英] Can I pass the viewbag value to the jQuery in mvc2

查看:72
本文介绍了我可以viewbag值传递给jQuery的在MVC2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的值传递给jQuery的使用viewbag的看法。我想实现的是通过空或某个值,然后jQuery的应该隐藏或显示在div取决于例如通过东西像下面的值:

I need to pass the value to jQuery in the view using viewbag. What I want to achieve is pass the null or some value and then jQuery should hide or show the div depending on the value passed for instance something like below:

viewbag.testNumber = null;
 $('#showdiv').hide();
  $('viewbag.testNumber').value == someinteger{

    $("#showdiv").show();
    else
    $("#showdiv").hide();
});
   <div id="showdiv"> Some Calculation </div>

此外,我想禁用在视图中viewbag如果该值为空,因为它给了空误差

Also I want to disable the viewbag in the view if the value is null , because it gives null error

推荐答案

ViewBag仅在ASP.NET MVC 3,所以你不能使用,但可以使用的ViewData:

ViewBag is only in ASP.NET MVC 3 so you can't use that, but you can use ViewData:

    $('#showdiv').hide();
      if ($("#" + '<%=ViewData["testNumber"]').value == someinteger){      
         $("#showdiv").show();
       }
        else {
            $("#showdiv").hide();
        }
    });
       <div id="showdiv"> Some Calculation </div>

这篇关于我可以viewbag值传递给jQuery的在MVC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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