如何在MVC中按ID搜索 [英] How can I act to search by ID in MVC
本文介绍了如何在MVC中按ID搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿打码员:
我有两个名为Team and Player的控制器,
我想要显示所有与TeamID匹配的玩家:
我在我的团队控制器中添加了以下内容:
< pre lang =sql> public ViewResult播放器( int id)
{
球队= context.Players.Single(x => x.TeamID == id);
return 查看(团队);
}
我创建了一个名为AllPlayers的视图,如下所示:
@ model FootBall.Models.Player
@ {
ViewBag.Title = AllPlayers;
}
玩家
但我不知道根据匹配的团队ID显示球员姓名的代码是什么。
请回答并帮助我提前...........提前谢谢
解决方案
Hey coders:
I have two controller named Team and Player ,
I want to show all player that matched by TeamID:
I added the following in my Team controller:
public ViewResult players(int id)
{
Player team = context.Players.Single(x => x.TeamID == id);
return View(team);
}
I created a view named "AllPlayers" as below:
@model FootBall.Models.Player
@{
ViewBag.Title = "AllPlayers";
}
players
But I don't know what would be the code to show the players name according to matched Team ID.
Please Answer and help me to ahead........... thanks in advance
解决方案
这篇关于如何在MVC中按ID搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文