我是 ASP.NET MVC 的新手,我被困在这里。我想创建一个超链接,以便当我单击电影名称时,它会转到详细信息页面,其中包含详细信息。我已经有 @HTML.ActionLink 到控制器中的 Details 类,但现在我不知道在 Details 类中放什么。我应该为类 Index 创建一个变量来进行比较吗?
这是操作方法Index
:
public ActionResult Index()
{
PAPEntities db = new PAPEntities();
MovieViewModel[] movies = db.MoviesData.Select(movie => new MovieViewModel
{
MovieID = movie.MovieID,
MovieName = movie.MovieName,
MovieDescription = movie.MovieDescription,
MovieCategory = movie.MovieCategory,
MovieYear = movie.MovieYear
}).ToArray();
return View(movies);
}
这是带有@HTML.ActionLink 的索引部分:
@foreach (var item in Model)
{
<tr>
<td>@Html.ActionLink(item.MovieName, "Details", "Movies", new { id = item.MovieID }, null)</td>
<td>@item.MovieCategory</td>
<td>@item.MovieYear
<td>@item.MoviePrice</td>
</tr>
}
</table>
我试图搜索它,但没有出现类似的东西,所以我有点卡住了
如果@Html.ActionLink
是为了命中控制器的Details
方法Movies
,而你说:
我已经有@HTML.ActionLink 到控制器中的 Details 类,但现在我不知道在 Details 类中放什么
为此,我建议在“电影”控制器中添加一个像这样的方法“详细信息”:
public ActionResult Details(string id) // might be 'int' if your MovieId is of integer type
{
//use LINQ to fetch the movie based on input 'id'
//return the information with the 'details' view as you did with the 'Index' method
}
希望我已经正确回答了您的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句