I am getting a null reference exception on the below line:
foreach (var povList in @Model.HomePovsList)
This is the code in my view:
@if (@Model.HomePovsList != null)
{
foreach (var povList in @Model.HomePovsList)
{
<li>
<img alt="" src="@FMAapp.Helpers.ConfigHelper.CDNHost@Url.Content(@FMAapp.Helpers.ConfigHelper.HomePovImage + @povList.ImageUrl)" />
<div class="orbit-caption">
<h2 class="shrink">@Html.Raw(HttpUtility.HtmlDecode(@povList.Headine))</h2>
<h2 class="shrink"><strong>@Html.Raw(HttpUtility.HtmlDecode(@povList.Headline1))</strong></h2>
<p>@Html.Raw(HttpUtility.HtmlDecode(@povList.SubHeadline))</p>
@if (povList.IsExternal != null)
{
<a class="button" href="http://@povList.LinkTo" target="_blank"> @povList.ButtonText</a>
}
else
{
<a class="button" href="@Url.Action(@Model.GetHomeFeaturePovLink(povList.LinkTo).Action, @Model.GetHomeFeaturePovLink(povList.LinkTo).Controller, new { PCTR = @Model.PCTR })">
@povList.ButtonText</a>
}
<p><small>@povList.Disclaimer</small></p>
</div>
</li>
}
}
In the controller I am assigning like this:
var currentPage = new PageProperties(PCTR) {
HomePovsList = new HomePovRepository().GetHomePovImages(PCTR)
};
new HomePovRepository().GetHomePovImages(PCTR)
returns an IList<Marketing_HomePov>
.
In my view model, I have this property:
public IList<Marketing_HomePov> HomePovsList
{ get; set; }