I trying get all data from my two tables but I have a lot of compile problems. Do you know where is it problem? Also I would like to declaration two tables here return "View(repository.Towar);" Now is visible one but I don`t know what should I do also this "se.Towar_zakupiony".
I found solution myself:
code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SportsStore.Abstract;
using SportsStore.Entities;
namespace SportsStore.WebUI.Controllers
{
public class ProductController : Controller
{
//
// GET: /Product/
public ITowarRepository repository;
public IKategorieRepository re;
public ProductController(ITowarRepository productRepository, IKategorieRepository kategorie)
{
repository = productRepository;
re = kategorie;
}
public ViewResult List()
{
SomeViewModel viewModel = new SomeViewModel
{
Towar = repository.Towar
.OrderBy(p => p.Id_tow),
Kategorie = re.Kategorie
.OrderBy(p => p.Id_kat)
};
return View(viewModel);
}
}
}
code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SportsStore.Entities
{
public class SomeViewModel
{
public IEnumerable<SportsStore.Entities.Towar> Towar { get; set; }
public IEnumerable<SportsStore.Entities.Kategorie> Kategorie { get; set; }
public IEnumerable<SportsStore.Entities.Zdjecie> Zdjecie { get; set; }
public IEnumerable<SportsStore.Entities.Typ_zdjecia> Typ_zdjecia { get; set; }
public IEnumerable<SportsStore.Entities.Zakup> Zakup { get; set; }
public IEnumerable<SportsStore.Entities.Adres> Adres { get; set; }
public IEnumerable<SportsStore.Entities.Status> Status { get; set; }
public IEnumerable<SportsStore.Entities.Towar_Zakupiony> Towar_zakupiony { get; set; }
}
}
code:
@model SportsStore.Entities.SomeViewModel
@{
ViewBag.Title = "List";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>List</h2>
@foreach (var p in Model.Towar)
{
<div class="item">
<h3>@p.Nazwa</h3>
@p.Opis
<h4>@p.Cena.ToString("c")</h4>
</div>
}
<h2>List</h2>
@foreach (var b in Model.Kategorie)
{
<div class="item">
<h3>@b.Nazwa</h3>
</div>
}