ASP .NET MVC 3 - How to submit an ajax form nested within an html form

≡放荡痞女 提交于 2019-12-06 23:18:57

问题


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


回答1:


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).



来源:https://stackoverflow.com/questions/10677322/asp-net-mvc-3-how-to-submit-an-ajax-form-nested-within-an-html-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!