Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a form with no default action using Html.BeginForm

I want to create a form which has no default action in it. I tried doing Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data", id = "AppForm" }) but it assigns the current action method name to the action part of the form and renders it as

<form class="ng-pristine ng-valid" id="AppForm" action="/Portal/on/application" enctype="multipart/form-data" method="post" novalidate="novalidate">

</form>

I have two separate buttons on the form and I am following this article http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework to create a form but not sure how to create one which has no action.

Thanks

like image 885
SP1 Avatar asked Sep 15 '15 17:09

SP1


People also ask

What is @using HTML BeginForm ()) in MVC?

Html. BeginForm is the Html Helper Extension Method that is used for creating and rendering the form in HTML. This method makes your job easier in creating form. Here, is the method to create a form using Html.

What is difference between HTML BeginForm and Ajax BeginForm?

BeginForm() will create a form on the page that submits its values to the server as a synchronous HTTP request, refreshing the entire page in the process. Ajax. BeginForm() creates a form that submits its values using an asynchronous ajax request.

What does HTML BeginForm do?

BeginForm(HtmlHelper, String, String, FormMethod, Object)Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes.

Which two objects can you passed as a parameter to the HTML helper Dot BeginForm method?

BeginForm() method has three arguments, these are actionName, controllerName and AjaxOptions.


1 Answers

Do you have to use Html.BeginForm()? You could just do it with html instead of using the HtmlHelper.

<form class="ng-pristine ng-valid" id="AppForm" action="" enctype="multipart/form-data" method="post" novalidate="novalidate">

</form>

If you have to use the HtmlHelper, you can override the form action like this:

@using(Html.BeginForm(null, null, FormMethod.Post, new { @action = "", enctype = "multipart/form-data", id = "AppForm" })) {

}
like image 169
Peter Avatar answered Oct 20 '22 23:10

Peter