Reputation: 49
I have a view that pulls data from a model and lists it as a set of links:
<p>@foreach (var genre in Model)</P
a href="@Url.Action("Index", "FullMovieList")"> class="genreItem">@Html.DisplayFor(modelItem => genre.GenreName)
My question is: how do I tell which genre has been clicked on the next page? Should i send the variable:
view -> genre controller -> fulllist controller -> view
and if so, how?
Upvotes: 2
Views: 84
Reputation: 218732
You can pass the genre in the querystring.
Use this overload of Url.Action
@Url.Action("Index", "FullMovieList",new { genre = genre.GenreName })
This will generate the url value with querystring like "/FullMovieList/Index?genre=someName"
Assuming your Index action method accepts a parameter named genre
and check the value of that and return a relevant response according to that.
public ActionResult Index(string genre="")
{
if(!String.IsNullOrEmpty(genre))
{
}
// to do :Return something
}
Upvotes: 6