Tadej Vengust
Tadej Vengust

Reputation: 1401

Post form to controller in MVC(Orchard)

I have a simple form:

<form actions="/module_name/controller_name/function_name" action="GET">
<input type="email" name="email" />
<input type="submit" value="send" />
</form>

And I have my controller:

[Themed]
    public class controller_name: Controller
    {
        [HttpGet]
        [AlwaysAccessible]
        public ActionResult function_name()
        {
            int b;
            return new EmptyResult();
        } 
    }

The data is only for testing. Because for unknown reason the post only redirect me to the page: localhost/module_name/controller_name/function_name?email=...

Instead of going into controller.

What am I doing wrong?

Upvotes: 0

Views: 546

Answers (1)

devqon
devqon

Reputation: 13997

You probably haven't set up routing for your module. Create a class that looks like this:

public class Routes : IRouteProvider {
    public void GetRoutes(ICollection<RouteDescriptor> routes) {
        foreach (var routeDescriptor in GetRoutes())
            routes.Add(routeDescriptor);
    }

    public IEnumerable<RouteDescriptor> GetRoutes() {
        return new[] {
            new RouteDescriptor {
                Priority = 5,
                Route = new Route(
                    "Test", // this is the name of the page url
                    new RouteValueDictionary {
                        {"area", "my_module"}, // this is the name of your module
                        {"controller", "controller_name"},
                        {"action", "function_name"}
                    },
                    new RouteValueDictionary(),
                    new RouteValueDictionary {
                        {"area", "my_module"} // this is the name of your module
                    },
                    new MvcRouteHandler())
            }
        };
    }
}

Upvotes: 2

Related Questions