I have a partial view that is rendered by several views which are returned by several action methods.
The partial view has a form that should post back to the called action method.
It is my understanding that if i just call
<% Html.BeginForm(); %>
from within a view, the form's action attribute will point to the called action method. I can't do this, because I need to set the form's ID attribute for javascript purposes. The overload of Html.BeginForm that will let me set html attributes also requires an explicit controller and action. So, instead of using the Html helper, I could just write the form element out like:
<form action="<%=(NEED TO SOMEHOW GET THE URL TO THE CURRENT ACTION) %>" method="post" id="myForm">
I'm just not sure how to get the URL.
Just pass null for the controller and action. The correct values will be substituted. E.g.:
<% using (Html.BeginForm(null, null, FormMethod.Post, new { id = "employeeGroupForm" }))
ViewContext.RouteData.Values["action"]
Or something similar gets the job done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With