简体   繁体   中英

Cannot perform runtime binding on a null reference in mvc

@if ((ViewBag.DynamicFields.Length == 0 )||((ViewBag.DynamicFields as ICollection<ChampModel.DynamicFields>).Where(o => o.Active == false).Count() == (ViewBag.DynamicFields as ICollection<ChampModel.DynamicFields>).Count()))
{
    <div class="info">
    @Html.Label("Dynamic fields were not assigned to this table")</div>
}

This error happens when you have a ViewBag property being nonexistent in your view.

See if there is a typo?

or just add check for null

 @if (((ViewBag.DynamicFields == null) ||(ViewBag.DynamicFields.Length == 0 )||((ViewBag.DynamicFields as ICollection<ChampModel.DynamicFields>).Where(o => o.Active == false).Count() == (ViewBag.DynamicFields as ICollection<ChampModel.DynamicFields>).Count()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM