且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在MVC中按ID搜索

更新时间:2022-10-20 22:38:24

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