.net Core服务端 接收html form post和get表单数据

以下是 .net Core服务端接收数据代码
using Microsoft.AspNetCore.Mvc;
namespace WebApplication1.Controllers
{
    public class TestController : Controller
    {
        public IActionResult CheckUser(string username, string userpassword)
        {
            return Content("帐号" + username + "密码" + userpassword);
        }
    }
}
//假设服务地址是https://localhost:5001

以下是 html form post和get 和送数据代码
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>SayHello</title>
</head>
<body>
<!--
以下form发送数据 跟在浏览器里面直接输入(Get请求)
https://localhost:5001/Test/CheckUser?username=lqwvje&userpassword=123456
的效果一样
-->
    <form action="https://localhost:5001/Test/CheckUser" method="post"><!--method="get"这是get发送-->
        用户名:<input type="text" name="username" value="lqwvje" />
        密码:<input type="password" name="userpassword" value="123456"/>
        <input type="submit" value="登录" />
    </form>
</body>
</html>

评论