How to check the contents of a bag for viewing in a razor

Is there a way to check the contents of the viewbag that the viewbag has data in the view. my controller sends, possibly, new data every time I press a button and send it with the same name.

here is my controller

public ActionResult Details(string IncomRequest, Int Id) { // some code...... switch (IncomRequest) { case ("Order"): ViewBag.Query = list<Ordr> Ord; break; case ("Process"): ViewBag.Query = lis<Process> pro; break; } return view(); 

In my opinion, I want to check whether the viewing bag contains Ord or pro.

+4
source share
2 answers

In your view, you can do something like this:

 // if this is true then there nothing there @if (ViewBag.Query == null) 

further you can do it:

 // it was set by the "Order" case @if (ViewBag.Query is List<Ordr>) 
+2
source

Yes, you can

 @if(ViewBag.Query is List<Ordr>) { // List<Ordr> } else if(ViewBag.Query is List<Process>) { // List<Process> } 
+2
source

Source: https://habr.com/ru/post/1481242/


All Articles