我有下一个特定的地图路线
routes.MapRoute(
"MyPagePost",
"URL-Up/{name}",
new { controller = "MyController", action = "MyPostAction" },
new { httpMethod = new HttpMethodConstraint("POST") }
);
routes.MapRoute(
"MyPageGet",
"URL-Up/{name}",
new { controller = "MyController", action = "MyGetAction" },
new { name = "[A-Za-z].+", httpMethod = new HttpMethodConstraint("GET") }
);
我的默认控制器看起来像
routes.MapRoute(
name: "Default",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", culture = "en", id = UrlParameter.Optional },
constraints: new { culture = @"[a-zA-Z]{2}" }
);
问题是下一个问题: 我的 MyPageGet 路由显示一个包含FORM的页面,其中POST需要返回 MyPagePost 路由,但在第一次调用时,我收到相同的GET请求,并在URL中查看其他额外参数?文化= DE。此外,无论有没有这个参数,第二次调用它都可以通过MyPagePost路由正常工作。
更新:
在Chrome或fiddler日志中,我看到对URL-Up/Bla-Bla
的重新审核有302状态,而且响应是 URL-Up / Bla-Bla?culture = de 。为什么无法处理?
答案 0 :(得分:1)
只需尝试
@using(Html.BeginRouteForm("MyPagePost",FormMethod.Post))
{
<input type="submit" value="Submit"/>
}
你的帖子中的路线第一次在html.beginform和html.beginrouteform中为我工作。
我尝试使用以下路线和行动方法
routes.MapRoute(
"MyPagePost",
"URL-Up/{name}",
new { controller = "Home", action = "PostAction" },
new { name="[A-Za-z].+", httpMethod = new HttpMethodConstraint("POST") }
);
routes.MapRoute(
"MyPageGet",
"URL-Up/{name}",
new { controller = "Home", action = "GetAction" },
new { name = "[A-Za-z].+", httpMethod = new HttpMethodConstraint("GET") }
);
routes.MapRoute(
name: "Default",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", culture = "en", id = UrlParameter.Optional },
constraints: new { culture = @"[a-zA-Z]{2}" }
);
public ActionResult GetAction()
{
return View();
}
[HttpPost]
public ActionResult PostAction()
{
return View();
}