Question

I have a form where model is displayed across multiple partial views, jQuery tabs is used,everything works fine except, validation summary doesn't view errors from all views.

If a user gets an error in first tab, moves to second tab, validation summary is overridden by errors in the last tab used.

If I don't use the jQuery tabs, it's working well.

How do I use tabs and make validation summary shared among the partial views/tabs ?

Main view:

@model Data

<script type="text/javascript">

    $(function () {
        $("#Tabs").tabs();
    });
</script>
<div id="Tabs">
    <ul>
        <li><a href="#tabs-Product">Product</a></li>
        <li><a href="#tabs-Filteration">Filteration</a></li>
    </ul>
    @using (Ajax.BeginForm(MVC.Products.Save(),
                           new AjaxOptions { HttpMethod = FormMethod.Post.ToString()}))
    {

        <div id="tabs-Product">
            @{ Html.RenderPartial(MVC.Products.Views.tabs._tabs_Product, Model);}
        </div>

        <div id="tabs-Filteration">
            @{ Html.RenderPartial(MVC.Products.Views.tabs._tabs_Filteration, Model);}
        </div>

        @Html.ValidationSummary(false)

     <input type="submit" value="Ok" />
    }
</div>
Was it helpful?

Solution

Use instead Pure CSS Tabs it has no javascript and wont meddle with the validation summary

CSS:

.tabs {
    position: relative;
    min-height: 570px; /* This part sucks */
    clear: both;
    margin: 25px 0;
}

.tab {
    float: left;
}

    .tab label {
        background: #eee;
        padding: 10px;
        border: 1px solid #ccc;
        margin-left: -1px;
        position: relative;
        left: 1px;
    }

    .tab [type=radio] {
        display: none;
    }

.content {
    position: absolute;
    top: 28px;
    left: 0;
    background: white;
    right: 0;
    bottom: 0;
    padding: 20px;
    border: 1px solid #ccc;
    overflow: hidden;
}

    .content > * {
        opacity: 0;
        -webkit-transform: translate3d(0, 0, 0);
        -webkit-transform: translateX(-100%);
        -moz-transform: translateX(-100%);
        -ms-transform: translateX(-100%);
        -o-transform: translateX(-100%);
        -webkit-transition: all 0.6s ease;
        -moz-transition: all 0.6s ease;
        -ms-transition: all 0.6s ease;
        -o-transition: all 0.6s ease;
    }

[type=radio]:checked ~ label {
    background: white;
    border-bottom: 1px solid white;
    z-index: 2;
}

    [type=radio]:checked ~ label ~ .content {
        z-index: 1;
    }

        [type=radio]:checked ~ label ~ .content > * {
            opacity: 1;
            -webkit-transform: translateX(0);
            -moz-transform: translateX(0);
            -ms-transform: translateX(0);
            -o-transform: translateX(0);
        }

View:

@using (Ajax.BeginForm(MVC.Products.Save(),
                            new AjaxOptions
                                {
                                    HttpMethod = FormMethod.Post.ToString()
                                }))
{
    @Html.HiddenFor(s => s.Id)

    @Html.ValidationSummary(false)

    <div class="tabs">

        <div class="tab">
            <input type="radio" id="tab-1" name="tab-group-1" checked="">
            <label for="tab-1">Product</label>

            <div class="content">
                @{ Html.RenderPartial(MVC.WhiteLabelTool.Symbols.Views.tabs._tabs_Product, Model); }
            </div>
        </div>

        <div class="tab">
            <input type="radio" id="tab-2" name="tab-group-1">
            <label for="tab-2">Filteration</label>

            <div class="content">
                @{ Html.RenderPartial(MVC.WhiteLabelTool.Symbols.Views.tabs._tabs_Filteration, Model);}
            </div>
        </div>


    </div>
        <input type="submit" value="Ok" />
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top