【发布时间】:2019-04-25 01:43:29
【问题描述】:
我有一个 asp.net core razor 页面,其中有一个简单的表单,要求输入用户电子邮件地址和提交按钮。当我输入电子邮件并单击提交按钮时,我总是收到 400 错误
HTTP 错误 400
我不确定我在这里做错了什么。我尝试在 OnPost 方法中放置一个断点,但我什至没有达到那个点。
下面是我的代码:
Homie.cshtml
@page
@model WebApplication1.Pages.HomieModel
@{
ViewData["Title"] = "Homie";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Homie</h1>
<form method="post">
<input type="email" name="emailaddress">
<input type="submit">
</form>
Homie.cshtml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApplication1.Pages
{
public class HomieModel : PageModel
{
public void OnGet(string n)
{
}
public void OnPost()
{
var emailAddress = Request.Form["emailaddress"];
// do something with emailAddress
}
}
}
【问题讨论】:
-
除了 400 之外,您在响应中看到任何其他信息吗?
-
@ChetanRanpariya no.. 没有
-
你能调试
OnPost的代码吗?您是否在浏览器中看到此错误?如果浏览器出现错误,您可以分享屏幕截图吗? -
@ChetanRanpariya 添加了屏幕截图。
标签: c# asp.net-core razor-pages