How to add a form in _Root.cshtml

Vote:
 

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?

using (Html.BeginForm("Login", "StartPageController", FormMethod.Post))
{
    <input required="required" type="text" id="loginHint" name="loginHint" value="" placeholder="Enter email">
    <button id="loginBtn" class="btn" type="submit">Login</button>
}
#251166
Mar 23, 2021 12:55
Vote:
 

I think "StartPage" instead of "StartPageController"...?

using (Html.BeginForm("Login", "StartPage", FormMethod.Post))
#251213
Mar 23, 2021 13:55
Helani Wanniarachchi - Mar 24, 2021 5:37
Still the same, getting 404.
Vote:
 

Hi,

Add Route using the initialization module and give it a try

[InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class MVCRoutesInitializationModule : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            MapRoutes(RouteTable.Routes);
        }

        private void MapRoutes(RouteCollection routes)
        {
            routes.MapRoute(null, "login", new { controller = "StartPage", action = "Login" });
        }

        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }
#251287
Mar 24, 2021 12:52
Helani Wanniarachchi - Mar 25, 2021 10:21
Yes, it worked. Thanks
Ravindra S. Rathore - Mar 25, 2021 10:22
Great!
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.