.NET Core第22天_FormActionTagHelper的使用

FormActionTagHelper (窗体操作标记帮助程序) : 其非针对原生HTML任何TAG对应的封装,功能是生成formaction属性

在<button>、<input type=image>tag中,

用於
控制<form>中在何处提交资料。换言之,可以不一定将action属性设置URL跳转固定放在<form>tag层级当中。(一个表单可以提交至不同server上进行处理)

https://ithelp.ithome.com.tw/upload/images/20210922/20107452uyYuWdn9Ni.png

新建好FormActionController跟相应Index检视
预设我们可以观察到在<button>有产生对应formaction各自对应不同导向URL

https://ithelp.ithome.com.tw/upload/images/20210922/20107452usiqcKzo6o.png

接下来调整一下检视,提交表单<button>必须放置於<form>里面才能提交。

新增TeacherController.cs

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Net5App6.Controllers
{
    public class TeacherController : Controller
    {
        public string Home(string name, string age)
        {
            return $"Teacher控制器下的Home Action, 名字:{name},年龄:{age}";
        }
    }
}

新增StudentController.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 StudentController : Controller
    {
        public IActionResult Info(string name,string age)
        {
            ViewBag.Name = name;
	    ViewBag.Age = age;
            return View();
        }
    }
}

Info View

<div>
    <p>Student Info</p>
    <p>@ViewBag.Name</p>
    <p>@ViewBag.Age</p>
</div>

https://ithelp.ithome.com.tw/upload/images/20210922/201074529zqQ401HKX.png

https://ithelp.ithome.com.tw/upload/images/20210922/20107452adDCU1I1fv.png

https://ithelp.ithome.com.tw/upload/images/20210922/20107452a3rnPNjyog.png

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


<<:  Day8 资料监听

>>:  Day 07 - Spring Boot 常用依赖

第26天 - 文件审核系统(4)_删除档案的部分

删除档案的部分,首先要先把栏位列印出来 资料表一样参考第23天的文章 https://ithelp....

Day28 修复老照片

修复老照片 教学原文参考:修复老照片 这篇文章会介绍在 GIMP 使用「仿制工具」和「着色滤镜」,将...

DE2_115(DAY1)以niosii去控制板子上的led灯

从学校拿到一块DE2_115,之前修DCLAB的时候只有接触Verilog的部分,现在想要学习板子上...

建构 Spring boot 容器 Image

要将自己开发的应用程序容器化,想必需要制作自己的 Image。制作 Image 也是一种艺术,我们要...

Day44. 范例:文字积木 (蝇量模式)

本文同步更新於blog 情境:这是公司生产的文字积木 <?php namespace Ap...