Umbraco SurfaceController model state / model validation issues
<p>In Umbraco I can hook up MVC partials with a <code>SurfaceController</code> that either looses model state on re-rendering after a post back, or validates the model prematurely and so displays validation errors for <code>@Html.ValidationMessageFor</code> helpers on the initial page rendering. What I really want is behaviour consistent with vanilla MVC partials and models.</p>

<p>I'm creating MVC partials for use in Umbraco supported by a <code>SurfaceController</code> to handle rendering and post-back.</p>

<p>I then wrap these partials in "Macros" so they can be dropped into page content alongside other content, rather than creating a special Document Type for each special page required (there would be a lot).</p>

<p>Partial:</p>

<pre><code>@using SomeProject.Web.Controllers
@model SomeProject.Web.Models.Identity.UserModel

@using (Html.BeginUmbracoForm&lt;IdentitySurfaceController&gt;("RegisterDetailsSubmit", null, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    @Html.EditorFor(model =&gt; Model)

    &lt;div class="form-group"&gt;
        &lt;div class="col-md-offset-2 col-md-10"&gt;
            &lt;input type="submit" class="btn btn-primary" value="Register" /&gt;
        &lt;/div&gt;
    &lt;/div&gt;
}
</code></pre>

<p>Macro:</p>

<pre><code>@inherits Umbraco.Web.Macros.PartialViewMacroPage
@Html.Action("RegisterDetails", "IdentitySurface")
</code></pre>

<p>SurfaceController:</p>

<pre><code>using SomeProject.Web.Models.Identity;
using System;
using System.Web.Mvc;

namespace SomeProject.Web.Controllers
{
    public class IdentitySurfaceController : Umbraco.Web.Mvc.SurfaceController
    {

        [ChildActionOnly]
        public ActionResult RegisterDetails(UserModel model)
        {
            if (model == null || model.Id == Guid.Empty) model = new UserModel(GetUser());

            return View(model);
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult RegisterDetailsSubmit(UserModel model)
        {
            if (ModelState.IsValid)
            {
                ...
            }

            return CurrentUmbracoPage();
        }

    }
}
</code></pre>

<p>When I use:</p>

<pre><code>[ChildActionOnly]
public ActionResult RegisterDetails()
</code></pre>

<p>I loose model state when rendering after a post back. User edits are lost.</p>

<p>When I use:</p>

<pre><code>[ChildActionOnly]
public ActionResult RegisterDetails(UserModel model)
</code></pre>

<p>Validation occurs early so I see validation errors everywhere as if a post back has already occurred. When setting break points in the code I can see the SurfaceController code is called first before hitting the partial view. In the partial view the model is populated, but for some reason all the validation messages get displayed as if the model is empty. If I do a post back, model state is preserved and everything displays as expected - validation messages for bad model properties, no messages for good model properties.</p>

<p>I see validation messages for all <code>@Html.ValidationMessageFor</code> items, and also valid model properties in all <code>@Html.EditorFor</code> items that accompany them.</p>

<p>Any idea what I might be doing wrong?</p>