简体   繁体   中英

Passing a Variable Between Views

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?

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM