0

I have a Razor view that contains a normal form using Html.BeginForm. It also uses Html.RenderAction to insert a partial view that contains another form. I'm using RenderAction so the partial view can be strongly typed with it's own model. That partial view contains an ajax form using Ajax.BeginForm.

The problem I'm having occurs when the regular form in the parent view posts and has validation errors returned from the controller method. The ajax form validates as well and displays its own error messages. At first I thought it was just client-side validation picking up both forms, but when I set a breakpoint, I found that the controller method the ajax form posts to was getting called as well.

I would prefer to keep this view simple and not use ajax for both forms. For the same reason, I would rather not combine the forms into one and use javascript or other methods to differentiate between the two. What are my other options to keep the ajax form from posting or validating when the regular form posts?

  • 1
    Are you rendering the partial (with the `AJAX.BeginForm` and its submit button) within the main views `
    ` tags?
    –  Sep 19 '14 at 23:16
  • @StephenMuecke, nope. I suspect that some of the problem is the call to Ajax.BeginForm occurs within the same request, and since the request is a post... – TheOtherTimDuncan Sep 19 '14 at 23:38

1 Answers1

0

My comment to @StephenMuecke finally triggered the right idea for the right keywords to google. And of course, the answer was already on StackOverflow. See Html.RenderAction uses Post instead of Get or How can I get Html.RenderAction to call the Get method on a Post?. @AndrewBarber's answer on the second link was a good answer. After I gave the GET and POST action methods for the ajax form different names and removed the [HttpGet] from the GET action method to allow it be called using either GET or POST, both forms work as expected.

Community
  • 1
  • 1