mardi 13 novembre 2018

filter mvc view using checkbox

trying again and se if someone now a solution to my problem

I am using mvc, Visual Studio 2017 and have made an tv-tableau that show the programs of 5 channels. My data is stored in a table (full) and look something like this:

ID.     Channel     Program         Date          Time
1       One         News         2018-11-11       18:00
2       One         Sport        2018-11-11       20:00
3       Two         Inception    2018-11-11       09:50
4       Three       Seinfeldt    2018-11-11       11.00
5       Four        Alf          2018-11-11       15:30
5       Four        News         2018-11-11       19:00
.
.
.

This is my Controller

namespace Uppgift4.Controllers
{
public class FullsController : Controller
{
    private TvProgramDBEntities db = new TvProgramDBEntities();

    public ActionResult Index()
    {
        return View(db.Full);
    }

This is My View

@model IEnumerable<Uppgift4.Models.Full>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>

<table class="table table-bordered table-hover">
<tr>
    <th>
        Channel
    </th>
    <th>
        Program
    </th>
    <th>
        Date
    </th>
    <th>
        Time
    </th>
    <th></th>
 </tr>

 @foreach (var item in Model)
 {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Channel)
        </td>
        <td>
           @Html.DisplayFor(modelItem => item.Program)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Date)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Time)
        </td>
    </tr>
 }

This code works fine and i get a list of all my programs for my 5 channels in my index view.

Now come my problem.. I want to be able to filter this table, by adding 5 checkboxes in my view(one for each channel), so i can choose which channel i want to show data from. So when i for example check channel One and two i just get the programs for this two channels in my view, How can i add this feature in my view? Anyone now a good way to. go?




Aucun commentaire:

Enregistrer un commentaire