ASP.NET MVC第010天_Model介紹(2)_檢視接收多筆MVC Model資料

若要在View上呈現多筆資料 則可以 Step1.預期會有多筆的Model Class先設計好 這裡用的是一個CountryCity的Class 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 using System ; using System.Collections.Generic ; using System.ComponentModel.DataAnnotations ; using System.Linq ; using System.Web ; namespace MVCWebApp1.Models { public class CountryCity { [Required] [Display(Name ="城市")] public string City { get ; set ; } [Required] [Display(Name ="國家")] public string Country { get ; set ; } } } Step2. 在Controller中可以去建立一個ActionResult 函數 返回一個會傳遞某Model陣列的View 1 2 3 4 5 6 7 public ActionResult CountryList () { CountryCity[] cities = new CountryCity[] { new CountryCity() { City = "台北市" , Country = "中華民國台灣" }, new CountryCity () { City = "新北市" , Country = "中華民國台灣" }, ...