Witajcie,
Tworzę właśnie w ASP.NET MVC4 (C#) aplikacje katalog filmów.
Chcę zrobić listę filmów/kategorii/etc. w formie tabeli, którą będzie można sortować po kolumnach, do tego celu wszyscy polecają WebGrid.
Niestety przerobiłem już kilka tutoriali i niestety nie mogę stworzyć takiej tabeli...
Kontroler wygląda tak:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MovieStore.Models;
namespace MovieStore.Controllers
{
public class GenreController : Controller
{
private MovieStoreContext db = new MovieStoreContext();
//
// GET: /Genre/
public ActionResult Index()
{
return View(db.Genres);
}
}
Widok:
@model IEnumerable<MovieStore.Models.Genre>
@{
ViewBag.Title = "Index";
}
<h2>Kategorie</h2>
<div class="CategoryList">
<p>
@Html.ActionLink("Utwórz nową kategorię", "Create")
</p>
<table>
<tr>
<th>
ID
</th>
<th>
Nazwa Kategorii
</th>
<th>
Operacje
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(ModelItem => item.GenreID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.ActionLink("Edytuj", "Edit", new { id=item.GenreID }) |
@Html.ActionLink("Usuń", "Delete", new { id=item.GenreID })
</td>
</tr>
}
</table>
</div>
@{WebGrid grid = new WebGrid(Model);}
@{grid.GetHtml();}
Tabela tworzona za pomocą foreach'a pięknie działa, jednak po tabeli tworzonej za pomocą WebGrid'a nie ma na stronie śladu - żadnego błędu VS czy serwer nie rzuca. Jak zmusić webgrid'a do działania ?