Reputation: 43077
I am pretty new in C# (I came from Java) and I have the following doubt about how .NET handle forms in .cshtml file.
In a view named Index.xshtml I have something like it:
@using (Html.BeginForm("Index", "Vulnerability", FormMethod.Post, new { id = "MyForm" }))
{
<div class="ui-field-contain">
<label for="Filter_CVE">CVE:</label>
<input type ="text" data-mini="true" data-clear-btn="true" id="Filter_CVE" name="Filter.CVE" value="@Model.Filter.CVE" />
</div>
<div data-role="controlgrup" data-type="horizontal" data-mini="true">
<input type="reset" data-inline="true" data-mini="true" value="Reset" />
<input type="submit" data-inline="true" data-mini="true" value="Seach" data-icon="search" />
</div>
}
Now it is pretty clear for me that this code create a form and 2 buttons. My doubt is related tho this line
@using (Html.BeginForm("Index", "Vulnerability", FormMethod.Post, new { id = "MyForm" }))
Looking to the official documentation (here: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.formextensions.beginform%28v=vs.118%29.aspx) I can't find my situation.
So what is the meanining of the previous BeginForm method parameters?
I think that they could be:
Index: it represent the page name? (my view is named **Index.xshtml)
Vulnerability: what represent?
FormMethod.Post: I think that this specify that the form sending is POST
new { id = "MyForm" }: what is this?
Upvotes: 0
Views: 1145
Reputation: 18620
Index: this is the name of your action
Vulnerability is the name of your controller
FormMethod.Post means the form is sent via POST
new { id = "MyForm" } are the html attributes, in this case the <form>
tag wil get an ID of MyForm
Imagine you have the following code in your VulnerabilityController
:
public ActionResult Index() {
}
Your form will send all the data entered in the HTML input fields to the Index action (by POST)
Upvotes: 1
Reputation: 18769
Index: This is your View
, and will be represented in the controller as an Action Method
Vulnerability: This is your controller
FormMethod.Post: This sets the form Method
new { id = "MyForm" }: This will set the id of the form, as in <form id="MyForm"
...
Upvotes: 1
Reputation: 4700
There's a documentation for that.
Method signature :
public static MvcForm BeginForm(
this HtmlHelper htmlHelper,
string actionName,
string controllerName,
FormMethod method,
Object htmlAttributes
)
Type: System.String The name of the action method.
Type: System.String The name of the controller.
Type: System.Web.Mvc.FormMethod The HTTP method for processing the form, either GET or POST.
Type: System.Object An object that contains the HTML attributes to set for the element.
Upvotes: 3