Is Html.BeginForm () required?

What does Html.BeginForm()

it do and is it necessary?

+2


source to share


3 answers


Essentially, it issues

<form>

      

to HTML output. The form tag is required if your POST pages (i.e. the button is clicked to submit the form) so that the browser knows where to submit the form. The reason it might work for you right now is because you might not have buttons - jsut links (I don't know what your application is, so just guess here).



In short: if you want to provide a form for an action, yes, this tag is required. If you do this via links, you don't need a form tag, and therefore, you really don't need a BeginForm.

NTN.

PS read Scott Guthrie's ASP.NET MVC blog posts, they will really get you started.

+5


source


BeginForm () simply writes out the form tag using the parameters provided to it. If you don't have a form, you won't or will do all of your interactions with AJAX, you may not need to. If you only have links on the page, then the form is not needed. However, if you are not using AJAX, you cannot make POST requests to your controller actions without using it to enter your form tag or manually enter your form tag.



+3


source


It is not necessary at all. It's just a helper that handles the creation of form tags. It's a good idea to use it though. My intuition is that they will improve this helper to handle things like XSS attacks and the like that you currently have to deal with using the AntiForgeryToken helper and its associated attribute.

0


source







All Articles