Reputation: 191
I'm having a problem with setting up correctly route in my home controller. I'm trying to set route for my email sing up input field. Here is my cshtml code snippet:
<form method="post" action="/home/emailsignup">
<input type="text" class="form-control" name="email" placeholder="[email protected]">
<span class="input-group-btn btnstateless">
<input type="submit" id="mailSignup"value="SUBSCRIBE"/>
</span>
</div>
</form>
I'm trying to set route for action in my HomeController.cs Here is the part of my code:
[Route("home/emailsignup")]
[HttpGet]
public ActionResult EmailSignupGet()
{
var cVM = new ConfirmedViewModel
{
confirmationTitle = "Thanks!",
message = "",
nextStep = "<a href=\"/\">Return home</a>"
};
return View("Confirmed", cVM);
}
[HttpPost]
public ActionResult EmailSignup(string email)
{
if (UtilsClass.IsValidEmail(email))
{
Email.GreenArrowHelper.AddOrUpdateUserByEmailFetchAllInfo(email).ConfigureAwait(false);
var cVM = new ConfirmedViewModel();
cVM.confirmationTitle = "Thanks!";
cVM.message = "";
cVM.nextStep = "<a href=\"/\">Return home</a>";
return View("Confirmed", cVM);
}
else
{
ErrorViewModel eVM = new ErrorViewModel
{
title = "Hmm, something's not right.",
message = "That doesn't look like a valid email address. Please try again.",
nextstep = "<a href=\"/\">Return home</a>"
};
return View("Error", eVM);
}
}
I'm trying to return my messages but instead, I'm getting HTTP 404 on click on subscribe button.What am I doing wrong?
Upvotes: 1
Views: 38
Reputation: 247153
You are missing the route on the post action
//POST home/emailsignup
[Route("home/emailsignup")]
[HttpPost]
public ActionResult EmailSignup(string email) {
//...
}
When using attribute routing on a controller you need to apply it to the desired actions else get the 404 not found as you already encountered.
Upvotes: 1