prasanna p

prasanna p

  • 980
  • 470
  • 103.9k

Viewbag null condition check giving error in the view

Jan 13 2020 11:44 AM
Hi Friends, I am assigning value in the controller like this. [HttpPost] public Actionresult order(FormColletion formcollection) { Viewbag.startes = formcollection ["starters"]; return view(); } Value of my viewbag is : gobi Manchuria,chicken 65 In my view What I am doing is @if(Viewbag.startes !=null) { @foreach(var data in (string)viewbag.starters.split(',')) //assigning data values here } Now my question is if viewbag not contains values giving @symbol error if I remove null check condition giving object reference error. What is the solution for this issue??

Answers (1)