How does the controller transfer information between the model and the view?

In ASP.NET MVC, how does the controller pass information between the model and the view?

Say I have a list of baseball players in my database. After I ask these players using LINQ in the controller, how do I then pass this information to view (my list of baseball players and their statistics)?

And after I pass them to the view, how do I use the inline code in the html views to scroll and display it?

+3
source share
2 answers

The controller has a ViewData field that you can use. This is a dictionary, and you can use it like this:

ViewData ["players"] = yourList;

ViewData :

<? foreach(var player in ViewData["players"] as List) {} ?>

, ViewPage ViewPage <T> , T - . return View() ViewModel.

+4

ASP.NET MVC http://www.asp.net/learn/mvc/, , 3 , .

+1

Source: https://habr.com/ru/post/1702733/


All Articles