jeudi 24 décembre 2015

Html.ValidationSummary and Ajax.BeginForm Best Practices

When some of the validation errors are client side and the others are server side, the client side errors goes into the @Html.ValidationSummary placeholder in the main view while the server side ones goes into the @Html.ValidationSummary which located on the action partial view.

If i'm not specifying @Html.ValidationSummary as part of the form action partial view, no server side errors shown at all.

how can i merge all the errors (client and server side) into one div located outside of the UpdateTargetId element?

@using (Ajax.BeginForm("PartialViewAction", "MyController", new AjaxOptions { UpdateTargetId = "AjaxResult"}))
{
        <div class="ValidationSummary">
            @Html.ValidationSummary()
        </div>

           <div class="ChartCriteriaSideBox">      
                <div>
                    <ul class="none">
                        <li>
                            @Html.RadioButtonFor(m => m.datesRange.PeriodTypeId, (int)DatesRange.PeriodType.RecentMonth, new { @checked = "checked" }) Recent Month
                        </li>
                        <li>
                            @Html.RadioButtonFor(m => m.datesRange.PeriodTypeId, (int)DatesRange.PeriodType.RecentYear) Recent Year
                        </li>
                        <li>
                            @Html.RadioButtonFor(m => m.datesRange.PeriodTypeId, (int)DatesRange.PeriodType.BetweenDates) Range
                        </li>
                    </ul>
                </div>
    </div>
      <input type="submit" />
    }

Aucun commentaire:

Enregistrer un commentaire