.NET Core第20天_TextAreaTagHelper的使用
TextAreaTagHelper : 可以換(多)行的輸入框,為.net 對html <textarea>的封裝。
新增一個TextAreaController 跟相應View和 ViewModel
TextAreaController.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | using Microsoft.AspNetCore.Mvc; using Net5App6.Models; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Net5App6.Controllers { public class TextAreaController : Controller { public IActionResult Index() { return View(); } [HttpPost] public IActionResult Index(TextAreaViewModel model) { string content = model.Content; return View(model); } } } |
Index.cshtml
1 2 3 4 5 6 7 8 9 | @model TextAreaViewModel <form method="post"> <div> <textarea asp-for="Content"></textarea> </div> <div> <input type="submit" value="提交" /> </div> </form> |
TextAreaViewModel.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; namespace Net5App6.Models { public class TextAreaViewModel { [Display(Name = "多行輸入框")] public string Content { get; set; } } } |
運行效果
留言
張貼留言