Search code examples
c#asp.net-mvchtml-helperhtml.beginform

How to submit a form in MVC with nested Beginforms?


My MVC application currently has an Html.Begin form in order to submit a form. Now there is a nested BeginForm in order to display the radiobuttonlist. My issue is when I hit Save, it doesn't hit my HttpPost action method. How can I solve this problem?

Thanks.


Solution

  • While you might be able to do stuff like this in Angular, you can't do this for server-side forms. You can have more than one form on a page but they can't be nested.

    You'll have to remove the inner form tags and deal with both type of post in the same controller action. Create some logic that works out what button was pressed and returns an enum called something like PostAction, then in your controller you can have a section of code for each type of action.