ASP.NET MVC 4 - Cannot Perform Runtime Binding On A Null Reference


Answer :

OK I am posting the full answer here -

  1. Try @ before if(@ViewBag.Stats[index] == null){ and remove @ from @ViewBag inside the if so that it look like this - @if(ViewBag.Stats[index] == null){

  2. You are setting index = 0, inside foreach, so it is initialised in every loop. Initialise it outside foreach like this

    var index = 0; foreach ...

if you are facing problem for the scope try this -

@{     var index = 0;     foreach (....) {         .......         index++     } } 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?