not valid, but I would like to get similar functionality. I have a form u...">

"nested" forms in MVC

I understand that nested tags are <form>

not valid, but I would like to get similar functionality.

I have a form used to create a user profile and on this form I would like to allow the user to specify one or more schools they attended.

In my current setup (below) I can only submit one school per form. I've removed validation and labels from my view to simplify this issue.


<% using (Html.BeginForm())
   { %>
        <legend>Basic Information</legend>
        <%: Html.EditorFor(m => m.Name) %>
        <!-- more input fields-->
        <%: Html.EditorFor(m => m.SchoolName) %>
        <!-- more input fields -->
        <input type="submit" value="Create" />
<% } %>


This view is strongly typed for ProfileViewModel

, which contains all property fields. My controller contains a very simple activity Create

that saves the entries to the database. This works great.

What I would like to do is allow the user to add multiple schools using this form. In, I used UpdatePanel to achieve what I want, but everything I've read suggests that it is standard in MVC to use PartialView and jQuery / ajax calls.

  • If I were to include the Schools section of my form in the PartialView, how would I get this PartialView, which is nested in another form, to “submit” and “update” without affecting the main view?
  • How do I change my view models to reflect this? Should I save List<School>

    in ProfileViewModel

    that contains all the added schools, or is there a better way? Should I pass SchoolViewModel to PartialView?

source to share

1 answer

You can take a look at the following article .



All Articles