Hello. We master asp.net. Received from the MSSQL database a list of users (names). Now the task is to make every name clickable with viewing the detailed information of each user from the database. Please show me an example, or relevant information about this.

  • Hello. You here - tym32167

1 answer 1

Well, as an option, you can try to return the controller to the user info view as well.

public ActionResult Index() { ViewBag.Users = context.Users.ToList(); return View(); } 

then in the view make a list

 <div class="col-md-4"> <ul> @foreach (var user in ViewBag.Users) { <li><span>Пользователь: @user.Name </span>@Html.ActionLink("Подробнее", "UserInfo", new { Id = user.Id})</li> } </ul> </div> 

then, when clicked, the request goes to the UserInfo method where the Id of the user is transferred; it will be received from the database and transferred to the view that will be returned by the UserInfo method

 public ActionResult UserInfo(int id) { ViewBag.User = context.Users.FirstorDefault(g => g.Id == Id); return View(); }