I get the below excption:
Exception of type 'System.InvalidOperationException' occurred in System.Core.dll but was not handled in user code
Additional information: The sequence does not contain Elements.
at line
var kategoria = db.Kategorie.Include("Kursy").Where(k => k.NazwaKategorii.ToUpper() == nazwaKategori.ToUpper()).Single();
My KursyController.cs:
using SklepInternetowy1.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SklepInternetowy1.Controllers
{
public class KursyController : Controller
{
private KursyContext db = new KursyContext();
// GET: Kursy
public ActionResult Index()
{
return View();
}
public ActionResult Lista(string nazwaKategori)
{
var kategoria = db.Kategorie.Include("Kursy").Where(k => k.NazwaKategorii.ToUpper() == nazwaKategori.ToUpper()).Single();
var kursy = kategoria.Kursy.ToList();
return View(kursy);
//return View();
}
public ActionResult Szczegoly(string id)
{
var kurs = db.Kursy.ToList();
return View(kurs);
//return View();
}
[ChildActionOnly]
public ActionResult KetagorieMenu()
{
var kategorie = db.Kategorie.ToList();
return PartialView("_KategorieMenu", kategorie);
}
}
}
My Lista.cs
@{
ViewBag.Title = "Lista";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="strona">
@Html.Action("KetagorieMenu")
<img src="../Content/Images/dommaly.png" width="5%" height="5%" />
<a href="link">
Start > ASP.NET
</a>
@Html.Partial("_KursyList")
My _KategorieMenu.cshtml:
@model IEnumerable<SklepInternetowy1.Models.Kategoria>
@using SklepInternetowy1.Infrastructure
<tabela>
<wiersz>
@foreach (var kategoria in Model)
{
<komorka>
<a href="@Url.Action("Lista","Kursy", new { nazwaKategori = kategoria.NazwaKategorii.ToString() })"
style="background-image: url(@Url.IkonyKategoriiSciezka(kategoria.NazwaPlikuIkony)); ">
@kategoria.NazwaKategorii
</a>
</komorka>
}
</wiersz>
My _KursyList.cshtml:
@model IEnumerable<SklepInternetowy1.Models.Kurs>
@using SklepInternetowy1.Infrastructure
<div id="zawartosc">
<tabela>
<wiersz>
@foreach (var kurs in Model)
{
<komorka>
<a class="dodajDoKoszykaLink" href="@Url.Action("DodajDoKoszyka","Koszyk",new {id = kurs.KursID})">
</a>
@if (kurs.Bestseller)
{
}
<a class="kursSzczegolyLink" href="@Url.Action("Szczegoly","Kursy",new {id =kurs.KursID})">
<img class="kurs" src="@Url.ObrazkiSciezka(kurs.NazwaPlikuObrazka)" width="66%" height="66%" />
<h1>
@kurs.TytulKursu - @kurs.AutorKursu
</h1>
</a>
</komorka>
}
</wiersz>
</tabela>
How to solve this problem?