I am making a project about movies. I want the movietitles to be displayed in a list on the startpage, when you click on one of the listitems it should redirect to a subpage (Movie.cshtml) with the movietitle in the url. The information on that page should be title, genre, year and country for that specific movie.
My StartController.cs:
using IMDB.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace IMDB.Controllers
{
public class StartController : Controller
{
// GET: Start
public ActionResult Index()
{
var movieList = new List<Movies>();
movieList.Add(new Movies() { Title = "Terminator", Genre = "Action", Year = 1984, Country = "America" });
movieList.Add(new Movies() { Title = "Terminator II", Genre = "Action", Year = 1984, Country = "America" });
return View(movieList);
}
public ActionResult Movie(string title)
{
return View();
}
}
}
I have already configured RouteConfig.cs to include Title in the url:
routes.MapRoute(
name: "Default",
url: "{action}/{title}",
defaults: new { controller = "Start", action = "Index", title = "Title"
});
And the list of movies in my Index.cshtml:
@model List<IMDB.Models.Movies>
@{
ViewBag.Title = "Start";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Welcome to My Movie Database</h2>
<ul>
@foreach (var movie in Model)
{
<li>
@Html.ActionLink(movie.Title, "Movie", new { title = movie.Title})
</li>
}
</ul>
And this is my Movie.cshtml page:
@model IMDB.Models.Movies
@{
ViewBag.Title = "Movie";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>
<h2>@Html.DisplayFor(model => model.Title)</h2>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Title)
</dt>
<dd>
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Genre)
</dt>
<dd>
@Html.DisplayFor(model => model.Genre)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Year)
</dt>
<dd>
@Html.DisplayFor(model => model.Year)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Country)
</dt>
<dd>
@Html.DisplayFor(model => model.Country)
</dd>
</dl>
</div>
So my question is, how do I get that unique information from my list?