2

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>

ご覧のとおり、このフォームには POSTmethod が割り当てられています。これは、私が知る限り、Html.BeginForm の FormMethod 引数での FormMethod.Get の使用に反しています。

別のフォームをテストしているときに気づいたことの 1 つ (実際のフォームははるかに長いため、構文/動作がチェックアウトされているかどうかを確認するために非常に小さなフォームを挿入しました) は次のとおりです。

@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 に、2 番目のフォームを GET にしたように見えますが、2 番目のフォームを最初のフォームの中に入れています。

誰でも光を当てることができますか?

4

0 に答える 0