Dynamically add forms and have validation work
<p>I have a situation where I have a ViewModel that has a number of fields (As an example):</p>

<pre><code>public class myVM
{
     [Required(errorMessage="SomeMessage")]
     public string Name;

     [Required(errorMessage="SomeMessage")]
     public string Address;

     [Required(errorMessage="SomeMessage")]
     public string PhoneNumber;
}
</code></pre>

<p>In the real world its a bit more complicated.</p>

<p>The user is given a choice of what they are on the page to edit, Name Info, Address Info, Phone Number Info etc.</p>

<p>Each of those options corresponds to a partial view that is loaded with the form for each section.</p>

<p>The issue that I have is that if a user goes on and selects that they want to just edit the Name section, so only the name form is rendered they still get the validation messages for the Address and Phone numbers...</p>

<p>I know WHY this is happening, just not sure what the best way to get round it is?</p>

<p>UPDATE.</p>

<p>Noted that the above is unclear, these form parts (Partial views) are all loaded into one BIG form.</p>

<p>Something like this :</p>

<pre><code>@using (Html.BeginForm())
{

    @Html.ValidationSummary(false)

    Html.RenderPartial("Partials/_AddressForm", Model.Address);
    Html.RenderPartial("Partials/_Phonenumber", Model.PhoneNumber);

    &lt;input type="submit" value="SAVE"/&gt;

}
</code></pre>

<p>The resulting form is posted back into one action which does a ModelState.IsValid - Which of course validates the WHOLE model.</p>