.NET Core第20天_TextAreaTagHelper的使用

TextAreaTagHelper : 可以换(多)行的输入框,为.net 对html 的封装。

新增一个TextAreaController 跟相应View和 ViewModel

TextAreaController.cs

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

@model TextAreaViewModel
<form method="post">
    <div>
        <textarea asp-for="Content"></textarea>
    </div>
    <div>
        <input type="submit" value="提交" />
    </div>
</form>

TextAreaViewModel.cs

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; }
    }
}

运行效果

https://ithelp.ithome.com.tw/upload/images/20210920/20107452RTo2LjCR1H.png

本篇已同步发表至个人部落格
https://coolmandiary.blogspot.com/2021/08/net-core20textareataghelper.html


<<:  Windows相关篇

>>:  找LeetCode上简单的题目来撑过30天啦(DAY5)

Day 19 : 案例分享(6.2) 人事、差勤与薪资 - 组织架构、人事资料及个人合同管理

案例说明及适用场景 组织架构是由部门及职务做为骨架,员工就职於某一个职务 员工在企业的职务,就如同系...

Unity自主学习(十三):认识Unity介面(4)

今天继续来熟悉Unity介面~(ง •̀_•́)ง‼ 昨天了解了阶层管理区,今天打算接续着看游戏执行...

关於除错这件事

发达的工具会剥夺人的能力,能力被剥夺後经验会开始狭隘,狭隘的经验则会让思维开始产生死角,有死角的思维...

使用 MockK 做测试

接下来的测试将会需要用到 mocking 的 library ,在 Android 大家比较常用的是...

Day 24 - 用 canvas 画个时钟

前述 今天来画个时钟~!一样利用 requestAnimationFrame,再判断当前时间,每一秒...