I have an asp.net core razor page where I have a simple form that asks for a user email address and a submit button. When I enter the email and click the submit button I'm always getting a 400 error
HTTP ERROR 400
I'm not sure what I'm doing wrong here. I tried putting a break point right inside the OnPost method, but I'm not even getting to that point.
Below is my code:
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
}
}
}
OnPost
? Are you seeing this error in browser? Can you share the screen capture if the error in browser? – Quart