asp.net mvc - check member existence in Mvc ViewBag -
sometimes have check existence of member inside viewbag inside mvc view, see if problem action forgot assign member. inside razor view have:
@if(viewbag.utente.ruolo.sysadmin)
how can check viewbag.utente
defined?
you must check objects null or not. utente
, utente.ruolo
, utente.ruolo.sysadmin
may null:
@if (viewbag.utente != null) { if (viewbag.utente.ruolo != null) { if (!string.isnullorempty(viewbag.utente.ruolo.sysadmin)) { //viewbag.utente.ruolo.sysadmin has value..you can use } } }
Comments
Post a Comment