0

I try to check empty of ViewBag such as

@if (((IEnumerable<dynamic>)ViewBag.Episode).Count() > 0)
@if (Enumerable.Count(ViewBag.Episode) > 0)
@if (Enumerable.Any(ViewBag.Episode))
@if (ViewBag.Episode!= null)

It's not work. Please help, how to check empty or null.

Thankyou

In Controller

Community
  • 1
  • 1
  • 3
    Why don't you use a viewmodel instead? Anyway include your code as text, not as an image. You appear to never set `ViewBag.Checkins`, and you don't explain how this doesn't work. Please read [ask]. – CodeCaster Jun 13 '17 at 08:03
  • Where is your ViewBag.Checkins, it doesnt seem in picture – hasan Jun 13 '17 at 09:47

2 Answers2

0

It should be:

@if (((IEnumerable<DataRow>)ViewBag.Episode).Count() > 0)

If you using this extension method AsEnumerable.

teo van kot
  • 12,350
  • 10
  • 38
  • 70
0

Hi just for your information,ViewData and TempData require typecasting and null checking whereas ViewBag doesn't need such checking.

Karthik Elumalai
  • 1,574
  • 1
  • 11
  • 12