I am having trouble with an ASP.net MVC form Posting to an Action containing multiple parameters. The problem is only some of the parameters are being initialized.
The page has multiple forms each backed by a separate controller.
The controller action receiving the Post action looks like this
public ActionResult Create(int institutionId, int applicationId, [Bind(Prefix = "LogoutItem")]LogoutItemDetail logoutItemDetail)
The form looks like this:
<% using (Html.BeginForm<LogoutItemsController>( c => c.Create(0,0,null))) { %>
<%= Html.AntiForgeryToken() %>
<tr>
<td><%= Html.SubmitButton("btnAdd", "Add") %></td>
<td><%= Html.TextBox("LogoutItem.Path")%></td>
</tr>
<% } %>
EDIT Form action URL
/Applications/LogoutItems/Create/0/0
I have verified this url matches the route below with the MVC Route Debugger, and with VS Debugger.
And the route
routes.MapRoute(null, "Applications/{controller}/{action}/{institutionId}/{applicationId}/")
The current URL
Applications/Show?institutionId=1001&applicationId=3003
When I step through, the Create method,
- institutionId has a value of 1001,
- applicationId has a value of 0, and
- logoutItemDetail has the values of the form submission
Any ideas as to why the applicationId parameter does not appear to be initialized?
Edit
Doing a little more testing, I found that if i do not explicitly name the controller/action in the form
<% using (Html.BeginForm()) { %>
Every form in the page is Posted, and all of the correct parameter values. In this case, the forms action value is an empty string. This would be an acceptable solution if every form on the page was not also posted.