Replace contact form POST with async JS API endpoint
Deploy Staging / deploy (push) Successful in 1m10s

Add a POST /api/contact minimal API that returns JSON instead of relying
on the Razor Page's OnPostAsync full-page reload. The contact form now
submits via fetch(), showing an inline success or error message without
reloading the page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLdp8vEGVX6EKSDQPAx36a
This commit is contained in:
Francesco Lorenzo D'Amico
2026-08-19 18:26:41 +02:00
parent 46d36fcd04
commit 028e62407a
3 changed files with 74 additions and 54 deletions
-50
View File
@@ -1,62 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesMovie.Data;
using RazorPagesMovie.Models;
namespace RazorPagesMovie.Pages
{
public class BewerbungModel : PageModel
{
private readonly RazorPagesMovieContext _context;
public BewerbungModel(RazorPagesMovieContext context)
{
_context = context;
}
[BindProperty]
public string Name { get; set; } = string.Empty;
[BindProperty]
public string Email { get; set; } = string.Empty;
[BindProperty]
public string? Phone { get; set; }
[BindProperty]
public string? Subject { get; set; }
[BindProperty]
public string Message { get; set; } = string.Empty;
public bool ContactFormSubmitted { get; set; }
public void OnGet()
{
}
public async Task<IActionResult> OnPostAsync()
{
var contactMessage = new ContactMessage
{
Name = Name,
Email = Email,
Phone = Phone,
Subject = Subject,
Message = Message
};
if (!TryValidateModel(contactMessage, nameof(ContactMessage)))
{
return Page();
}
_context.ContactMessage.Add(contactMessage);
await _context.SaveChangesAsync();
ContactFormSubmitted = true;
return Page();
}
}
}