ASP.NET MVC 4 - Cannot Perform Runtime Binding On A Null Reference
Answer :
OK I am posting the full answer here -
Try
@beforeif(@ViewBag.Stats[index] == null){and remove@from@ViewBaginside theifso that it look like this -@if(ViewBag.Stats[index] == null){You are setting
index = 0, insideforeach, so it is initialised in every loop. Initialise it outsideforeachlike thisvar index = 0; foreach ...
if you are facing problem for the scope try this -
@{ var index = 0; foreach (....) { ....... index++ } }
Comments
Post a Comment