using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;
namespace WebApplication1.Models { public class UsersModel { public int ID { get; set; } public string Name { get; set; } public int Age { get; set; } } }
using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using WebApplication1.Models;
namespace WebApplication1.Controllers { public class HomeController : Controller { private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger) { _logger = logger; }
public IActionResult Index() { // 建立usersModel物件 UsersModel usersModel = new UsersModel() { ID = 1, Name = "YU HSIANG", Age = 25 }; // 傳入View return View(usersModel); }