Post MVC 中的控制器表单(Orchard)

Post form to controller in MVC(Orchard)

我有一个简单的表格:

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

我有我的控制器:

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

数据仅供测试。因为未知原因 post 只将我重定向到页面:localhost/module_name/controller_name/function_name?email=...

而不是进入控制器。

我做错了什么?

您可能还没有为您的模块设置路由。创建一个如下所示的 class:

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())
            }
        };
    }
}