在MVC / Orchard应用程序中使用Razor cshtml文件。
表单区域显示为:
@using (Html.BeginForm("Action", "Controller", FormMethod.Get, new { area = "Area.area"})) {
Html.AntiForgeryToken();
@Html.LabelFor(model => model.Value)
@Html.EditorFor(model => model.Value)
<div class="actions">
@Html.ActionLink("Do Something", "OtherAction", "Controller", new { area = "Area.area"}, new { @class = "button"})
<button type="submit">Submit</button>
}
这导致以下HTML:
<form action="/Location/URL" method="post">
<!---Editor Fields etc-->
<div class="actions">
<a class="button" href="/Location/OtherURL">OtherAction</a>
<button type="submit">Submit</button>
</div>
</form>
正如你所看到的,这个表单被分配了POST方法,据我所知,这与在Html.BeginForm的FormMethod参数中使用FormMethod.Get相反。
在测试另一个表单时我注意到的一件事情(真正的表单更长,所以我插入一个非常小的一个以查看语法/行为是否已检出)如下:
@using (Html.BeginForm("Action", "Controller", FormMethod.Get, new {area = "Area.area"})) {
<button value="submit">Test</button>
}
@using (Html.BeginForm("Action", "Controller", FormMethod.Get, new { area = "Area.area"})) {
Html.AntiForgeryToken();
@Html.LabelFor(model => model.Value)
@Html.EditorFor(model => model.Value)
<div class="actions">
@Html.ActionLink("Do Something", "OtherAction", "Controller", new { area = "Area.area"}, new { @class = "button"})
<button type="submit">Submit</button>
}
这导致以下结果:
<form action="/Location/URL" method="post">
<button value="submit">Test</button>
<form action="/Location/URL" area="Area.area" method="get">
<!---Editor Fields etc-->
<div class="actions">
<a class="button" href="/Location/OtherURL">OtherAction</a>
<button type="submit">Submit</button>
</div>
</form>
</form>
所以这似乎使第一个形式成为POST,第二个形成了GET但是将第二个形式放在第一个形式中。
任何人都可以放弃任何光明吗?