8

I have an ASP .NET MVC 3 project and a problem with one of my 'Create' views.

I have cascading drop-down fields that I have implemented with ajax forms.

The view is roughly speaking - like this:

@using (Html.BeginForm(...))
{
    @Html.MyDropDown1

    using (Ajax.BeginForm(...))
    {
        @Ajax.MyDropdown2
        <input type="submit" value="Select" />
    }

    using (Ajax.BeginForm(...))
    {
        @Ajax.MyDropdown3
        <input type="submit" value="Select" />
    }

    <!-- other form fields -->

    <input type="submit" value="Create" />
}

The problem is that the submit buttons inside the ajax forms actually submit the outer html form.

Is there any way to specify the name of the form I want to submit?

I thought about putting my ajax forms above my html form so there would not be any nesting - but I need the values of the drop-down's selected items in my html post.

Thanks, Pete

5
  • 4
    HTML <form>s cannot be nested. Commented May 20, 2012 at 21:23
  • 1
    Basically you are creating invalid HTML. You need to redesign what you are trying to do. Commented May 20, 2012 at 21:46
  • @Rudie my guess would be someone might downvote because nesting html tables shows a "lack of research effort". (I have not down voted this, but that sort of oversight won't get an upvote from me, either. Commented May 20, 2012 at 22:41
  • @Pete for ajax, you don't strictly need a form element at all. You can pull your data from your regular form fields and submit it with your ajax call. Admitedly, you can't do so while using those ajax helpera, but you can't use them like you are,anyway. Commented May 20, 2012 at 22:45
  • I did research before I posted - but I only found help regarding multiple submit buttons to different actions in 1 form. Commented May 20, 2012 at 23:16

1 Answer 1

9

As pointed out in comments you can't have nested forms. Remove all the using (Ajax.BeginForm(...)) bits, and handle your ajax calls through jQuery (or sth else).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.