เสร็จแล้วมาเพิ่ม HelloWorldController
Controllers/HelloWorldController.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
using Microsoft.AspNetCore.Mvc; using System.Text.Encodings.Web; namespace MvcMovie.Controllers { public class HelloWorldController : Controller { // // GET: /HelloWorld/ public string Index() { return "This is my default action..."; } // // GET: /HelloWorld/Welcome/ public string Welcome() { return "This is the Welcome action method..."; } } } |
บรรทัดที่ 10 : คืนค่าเป็น string
เรียกใช้ไปที่ https://localhost:5001/HelloWorld
จะเห็นหน้าขาวๆที่มีข้อความ This is my default action...
หรือ เรียกใช้ไปที่ https://localhost:5001/HelloWorld/Welcome
จะเห็นหน้าขาวๆที่มีข้อความ This is the Welcome action method...
Link