我有一个简单的形式:
<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();
}
}
这些数据仅用于测试。因为未知原因,帖子只将我重定向到页面:localhost/module_name/controller_name/function_name?电子邮件=。。。
而不是进入控制器。
我做错了什么?
您可能还没有为模块设置路由。创建一个如下所示的类:
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())
}
};
}
}