Reputation: 271
I have a issue with a view being populated from a WCF service into a partial view. Everything works just fine and the model contains the data necessary, but somehow it keeps getting this error. I can clearly see the value for the ProduktDto so it isn't null at all, but still says it is.
Have heard that the error could be in the connectionString so I include it here:
<add name="SpelDatabasContainer" connectionString="metadata=res://*/SpelDatabas.csdl|res://*/SpelDatabas.ssdl|res://*/SpelDatabas.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=SpelAffarenDatabas;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Havent found the answer for this after serious googling. Here is the code for the view:
@model List<SpelAffarWCF.ProduktDto>
<table class="table table-responsive">
<tr>
<th>Id</th>
<th>Namn</th>
<th>Beskrivning</th>
<th>Utgivningsår</th>
<th>MP</th>
<th>SP</th>
<th>Pris</th>
<th>Utgivare</th>
<th>Konsoler</th>
<th>Genres</th>
<th>Aktiv order antal</th>
</tr>
@foreach (var spel in Model)
{
<tr>
<td title="Spelets Id">@spel.Id</td>
<td title="Spelets jävla namn">@spel.Namn</td>
<td title="@spel.Beskrivning">För musen över mig..</td>
<td title="När det släpptes">@spel.Utgivningsår</td>
<td title="Multipläjer">@Html.CheckBox("checkboxMP", spel.Multiplayer)</td>
<td title="Singlpläjer">@Html.CheckBox("checkboxSP", spel.Singleplayer)</td>
<td title="Spelet kostar faktiskt såhär mycket">@spel.Pris</td>
<td title="Id: @spel.Utgivare.Id, Spel: @spel.Utgivare.Produkter.Count()">@Html.ActionLink(spel.Utgivare.Namn, "EditPublisher", new { id = spel.Utgivare.Id })</td>
@if (spel.Konsoler.Count() > 0)
{
<td>
@foreach (var konsol in spel.Konsoler)
{
<p class="cellEntity">@konsol.Namn</p>
}
</td>
}
else
{
<td>Ingen.</td>
}
@if (spel.Genres.Count() > 0)
{
<td>
@foreach (var genres in spel.Genres)
{
<p class="cellEntity">@genres.Namn</p>
}
</td>
}
else
{
<td>Ingen genre.</td>
}
@if (spel.SpelPerOrders.Count() > 0)
{
<td>
@foreach (var spelOrder in spel.SpelPerOrders)
{
<p class="cellEntity">Id: @spelOrder.OrderId, @spelOrder.Antal st</p>
}
</td>
}
else
{
<td>Finns inte i någon order.</td>
}
<td>
<input type="button" value="Lägg till i kundvagn" onclick="AddToCart(@spel.Id)" />
</td>
</tr>
}
</table>
Upvotes: 0
Views: 145
Reputation: 7135
The error indicates it's either the spel.Utgivare.Produkter.Count()
or spel.Konsoler.Count()
call; the parameter of the Linq Count
extension method is named source
.
Upvotes: 1