如何用 Html.BeginForm()命名窗体?

如何使用 Html.BeginForm()在 ASP.NET MVC 中为表单命名?因为我想通过 Javascript 发布它。我认为应该是类似 Html.BeginForm(id = "frm")的东西。

我尝试了以下方法:

Html.BeginForm(null,null,new{id="frm",name="frm})


Html.BeginForm(new{@id="frm",@name="frm})

但是上面的代码产生的输出如下:

<form action="/Main/Index/Id?name=Id" method="post">
86672 次浏览
Html.BeginForm(null, null, FormMethod.Get, new { name = "frm", id = "frm" })

You'll need to catch the form submit with your JavaScript

Taken from this answer: How to pass in ID with Html.BeginForm()?

Can you not just do:

Html.BeginForm(new {@id="Id", @name="Id"});

It can pay to search SO for answers as I've found many things I want to ask have already been encountered.

Using MVC2, this is what worked for me:

<% using (Html.BeginForm("Index", "Home", null, FormMethod.Post, new {@id = "myForm", @name = "myForm"})) {%>
@HTML.BeginForm("Target-ViewName where you want to post the page","Controller Name",new {@name="Name of the Form", id="ID of the Form"})
{ //form here
}