如何在View中检查所有viewbag是否为null [英] How to check all viewbag is not null in View

查看:645
本文介绍了如何在View中检查所有viewbag是否为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示所有viewbag!= null,即使单个Viewbag为null也会显示给出错误消息 

I Need have to display all viewbag != null, even a single Viewbag is null it will Display Given error message 

请任何人告诉我我该怎么做?????

please any one assest me How Can I Do?????




Darshan Kumar B

Darshan Kumar B

推荐答案

ViewBag的类型为DynamicViewDataDictionary(在System.Web.Mvc命名空间中)。这意味着您可以通过添加属性并引用这些相同的属性来与其进行交互。您可以将任何对象添加到视图包中,以便在视图中使用,例如

示例
要检查空值,您可以对属性运行简单的空检查。

ViewBag is of type DynamicViewDataDictionary (in System.Web.Mvc namespace). So that means you can interact with it by adding properties and referring to those same properties. You can add any object to the view bag for use on your view like this example To check for nulls, you would run a simple null check against the property.




上面,我将展示如何使用模式匹配与ViewBag中的值进行交互但你已经知道那是什么价值了。请记住,ViewBag将在服务器端执行。

Above, I show how you can use pattern matching to interact with the value that's in the ViewBag but you would already know what that value is. Bear in mind that ViewBag will be executed on server side.

我希望你觉得这很有用。

I hope you find this helpful.


这篇关于如何在View中检查所有viewbag是否为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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