views:

510

answers:

3

I use a view with two partial views inside.

<div id="matches">
    <% foreach (var item in Model)
       { %>
    <% Html.RenderPartial("RenderMatchesListRowUserControl", item); %>
    <% } %>
</div>
<div id="addMatchFormBox">    
    <% Html.RenderPartial("AddNewMatchUserControl");%>
</div>

The first partial view "RenderMatchesListRowUserControl" renders a simple div element (for a list of matches), the second one "AddNewMatchUserControl" renders a form to create a new match beneath the list:

Source of AddNewMatchUserControl:

<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>

<% using (Ajax.BeginForm("Create", new AjaxOptions
   {
       UpdateTargetId = "matches",
       InsertionMode = InsertionMode.InsertAfter,
       OnSuccess = "flashit",
       OnFailure = "renderForm"
   }))
   {%>
<fieldset>
    <legend>New Match</legend>
    <p>
        <label for="DurationBetweenMovesInDays">
            Dauer (in Tagen) zwischen den Z&uuml;gen:</label>
        <%= Html.TextBox("DurationBetweenMovesInDays")%>
        <%= Html.ValidationMessage("DurationBetweenMovesInDays", "*")%>
    </p>
    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
<% } %>

Depending on the ModelState, the controller returns the partial view for the new match entry or the partial view for the form, to display the model errors.

if (Request.IsAjaxRequest()) {
            return ModelState.IsValid ?    PartialView("RenderMatchesListRowUserControl", match) : PartialView("AddNewMatchUserControl");
        }

It works fine, till the ModelState become invalid. In this case the form will be rendered at the end of the matches list because of the updatetargetid refers to the div element which contains the matches list. To avoid this, the updatetargetid must be changed to refer the div element containing the form. But i have no idea how to do this.

A: 

OKay. There is no way to archieve this in that way. I solved it with jquery.

Herr W.
A: 

I have a similar issue. Can you maybe give me an idea of how you solved this?

Jerrie Pelser
A: 

I'm interested too. Exactly the same problem.

LeSaint