Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
モデルからコントローラーまで、データベースから製品のリストを取得しました。今、ボタンがクリックされたときにビューに表示したいと思います。リストを表示するためにどの HTML 要素を使用すればよいのか、またそれをビューに渡す方法がわかりません。
コントローラーでは、次のようにモデルを返すことでModelを に渡すことができます。View
Model
View
return View(model);
次に、ファイルの先頭に次のようにView指定します。model
model
@model [Model here]
次に、オブジェクトをループして、次のようにページに表示できます。
<ul> @foreach(var product from Model.Products){ <li>@product.Name</li> } </ul>