Html.BeginFormと/ oはコントローラとアクションを指定するwはHTML属性

StackOverflow https://stackoverflow.com/questions/1786610

  •  21-09-2019
  •  | 
  •  

質問

の清潔さなどのI

using (Html.BeginForm())

と憎しみHTML属性を追加すると、コントローラ、アクション、およびフォームメソッドを指定する必要があること。

using (Html.BeginForm("Action", "Controller", FormMethod.Post,
  new { id = "inactivate-form" })
使用Html.BeginFormに方法はありますし、

?HTMLを手動で他のすべてアップを配線せずにフォームの属性を指定します
役に立ちましたか?

解決

なぜあなたは単なるHTMLを使用しないのでしょうか?

<form id="inactivate-form" method="post" >
</form>

他のヒント

あなたは「のId-ED」形式を追加するカスタム拡張を作成することができます

public static MvcForm BeginIdedForm(this HtmlHelper htmlHelper, string id)
{
    return htmlHelper.BeginForm(null, null, FormMethod.Post, new Dictionary<string, object>() { { "id", id } });
}

使用法そしてちょうどになります。

using(Html.BeginIdedForm("inactiveate-form")) 

@ニック・オルセンアクションのための答えを使用null /コントローラのパラメータと同様に、

@Html.BeginForm(null, null, FormMethod.Post, new Dictionary<string, object>() {{ "id", id }}
彼らは、フォームと同じアクション/コントローラにしているBeginFormポスティングバックをから作成された場合です。

System.Web.Mvc.RouteValuesHelpers.MergeRouteValues方法は、最終的にアクションを調べRequestContext.RouteDatanullからコントローラの名前を呼び出し、

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top