using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using WebApplication1.Models;
namespace WebApplication1.Controllers { public class TestController : Controller { public IActionResult Index() { // 使用ViewData ViewData["Message"] = "Hello World!";
TestViewModel testViewModel = new TestViewModel(); testViewModel.Customer = new Customer() ; testViewModel.Customer.Name = "YU HSIANG"; testViewModel.Customer.Number = "A001"; testViewModel.Customer.Tel = "00-00000000";
testViewModel.Products = new List<Product>(); testViewModel.Products.Add(new Product() { Name = "PS4", Number = "P001", Price = 11000 }); testViewModel.Products.Add(new Product() { Name = "PS5", Number = "P002", Price = 15000 });
return View(testViewModel); } public JsonResult TestJsonResult() { return Json(new { data = 5 }); }
@model WebApplication1.Models.TestViewModel @* For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 *@ @ViewData["Message"]<br> @Model.Customer.Name<br> @Model.Customer.Number<br> @Model.Customer.Tel<br>
@model WebApplication1.Models.TestViewModel @* For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 *@ @ViewData["Message"]<br> @ViewBag.msg<br> @Model.Customer.Name <br> @Model.Customer.Number <br> @Model.Customer.Tel <br>