简体   繁体   中英

Partial View not being rendered in Tab navigation

I am trying to create a tab-based navigation but the partial view for different buttons is not rendering, just the first one.

This is my tabs view:

@model Franchise.Web.AMAdministrationModel
<nav class="tab-nav">
    <ul>
        <li class="tab tab1 @if (Model.SelectedTab == 1) { @Html.Raw("selected");  }" rel="1"><a>Contact Details</a></li>
        <li class="tab tab2 @if (Model.SelectedTab == 2) { @Html.Raw("selected");  }" rel="2"><a>Agencies</a></li>
        <li class="tab tab3 @if (Model.SelectedTab == 3) { @Html.Raw("selected");  }" rel="3"><a>Contract</a></li>
    </ul>
</nav>
<div class="spacer_0"></div>
<script>
$(document).ready(function () {
    @Model.jsToLoad

    $('.tab').click(function () {
        updateTab($(this).attr('rel'));
    });
});

function updateTab(tab) {
    $('.tab').removeClass('selected');
    $('.tab-content').removeClass('show');
    $('.tab' + tab).addClass('selected');
    $('.tab-content' + tab).addClass('show');
   if(tab>=2){
        $.ajax({
            url: '@Url.Action("detailstab")',
            type: 'Get',
            data: { id: @Model.AgentID, tab: tab },
            success: function (response) {
                $('.tab-content'+tab).empty();
                $('.tab-content' + tab).html(response);                
                if (tab == 3) {
                    $(".dz-form").dropzone({
                        url: "@Url.Action("upload")",
                        queuecomplete: function (file, response) {
                            showAlert('alert', 'success', 'Contract', 'Upload complete.');
                            setTimeout(function () {
                                window.location.href = '@Url.Action("edit/" + @Model.AgentID + "/photos")';
                            }, 1000);
                        }
                    });
                }
            }
        });
    }
}
</script>

When you click a tab it should redirect the code to the detailstab (and it does)

        [HttpGet]
        public ActionResult DetailsTab(int id, int tab)
        {
            AMAdministrationModel ama = new AMAdministrationModel();
            // to do claudio            
            var agent = _amadministration.GetHeadAgentDetails(id, UserSession.GetRegion());
            if (agent == null || agent[0].AgentID == 0)
            {
                ExLog.HandleException(new NullReferenceException("Head Agent " + id + " not found, please use the site navigation to find your way around!"));
            }
            else
            {
                if(tab == 2)
                {
                    return new EmptyResult();
                    //return partial view in the 3rd deplyment
                }
                else if (tab == 3)
                {
                    ama.AgentID = id;                    
                    ama.ContractStartDate = agent[0].JoinDate;
                    ama.ContractEndDate = agent[0].LeaveDate;
                    ama.UserPermission = _userpermission;
                    return PartialView("ContractPartial", ama);
                }
            }
            return new EmptyResult();
        }

But the view ContractPartial is not being rendered

This should show a different partial view for every different tab.

The first tab is always shown and rendered correctly, but the following 2 of them are not.

I have sorted the issue.

In the view of the first button of the tab I forgot to close one and it was wrapping up the containers of the other tabs as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM