When user fills out subscribe form or contact form and the form is not valid it redirects to the form view
The forms are a partial form which are in the index page, possibly the issue but I'm not sure how to solve - it is a single page application with two actions, subscribe and contact.
How can I get it to stay on the same page and show the error.
Here is the subscribe Form (Contact is similar)
@model SubscribeViewModel
<!-- Subscribe Form -->
<form asp-controller="Home" asp-action="Subscribe" method="POST" enctype="multipart/form-data">
<div class="form-row">
<div>
<input asp-for="Email" placeholder="Email address">
<span asp-validation-for="Email" class="help-block text-danger"></span>
</div>
<div>
<button type="submit">Subscribe</button>
</div>
</div>
</form>
Here is the Home Controller
//Subscribe
[HttpPost]
public IActionResult Subscribe(SubscribeViewModel vm)
{
if (ModelState.IsValid)
{
_mailService.SubscribeEmail(vm.Email);
return RedirectToAction("Index", "Home");
}
return - **What to do here??;**
}
// Send Mail
[HttpPost]
public IActionResult Contact(ContactViewModel vm)
{
if (ModelState.IsValid)
{
_mailService.SendEmail(vm.Name, vm.Email, vm.Subject, vm.Message);
return RedirectToAction("Index", "Home");
}
return - **And here?;**
}