You should be able to post to an action in a page as you're trying to do. There can be issues with posting to child controllers but pages usually work.
Can you post your controller code?
From what I've read around, you need to structure your BeginForm without a controller but with a reference to the target content type like so:
@using (Html.BeginForm("Login", null, new { node = ContentReference.StartPage }, FormMethod.Post))
{
// Form elements go here
}
Alternatively place the Login action on a base controller that all of your Page type controllers inherit from.
I think you should be able to do that if you create a plain MVC controller (inherit direct from Controller) and call its action method (epi's controller won't work).
While Stotty's response looks to be correct, I'll just throw out another option:
Do you need to use @Html.BeginForm()? How about just writing out the form tag?
<form method="post" action="@Url.ContentUrl(ContentReference.StartPage)Login">
<input required="required" type="text" id="loginHint" name="loginHint" value="" placeholder="Enter email">
<button id="loginBtn" class="btn" type="submit">Login</button>
</form>
I know it looks odd to just have the action name added after the closing parenthesis, but I haven't had any issues with this way of writing it.
Hello,
I need to add a small form with a textfield for email and login button, in the site header in the _Root.cshtml.
I tried to post from it to an action defined in the StartPageController, but it doesn't work, I get 404. What the best way to implement this?
https://creditcardsupportx.com/rooms-to-go-credit-card
https://creditcardsupportx.com/burlington-credit-card
https://creditcardsupportx.com/zulily-credit-card
thanks
jackyjoy