Select.cshtml

<body> <ul class="nav nav-tabs"> <li class="active" id="class1"> <a href="#tab_1_1" class="tbs" data-info="class1" data-toggle="tab" aria-expanded="true"> 1 класс </a> </li> <li class="" id="class2"> <a href="#tab_1_2" class="tbs" data-info="class2" data-toggle="tab" aria-expanded="false"> 2 класс </a> </li> <li class="" id="class3"> <a href="#tab_1_3" class="tbs" data-info="class3" data-toggle="tab" aria-expanded="false"> 3 класс </a> </li> </ul> <div id="tab_1_2"> @Html.Partial("~/Views/Work201615/_PartialClass1.cshtml") </div> <script type="text/jscript"> $('.tbs').on('click', function () { var info = $(this).data('info'); switch (info) { case 'class1': $('#tab_1_2').load("/Work201615/Class1"); //Controller method which returns partial view break; case 'class2': $('#tab_1_2').load("/Work201615/Class2"); //Controller method which returns partial view break; case 'class3': $('#tab_1_2').load("/Work201615/Class3"); //Controller method which returns partial view break; default: break; } }); </script> </body> 

_PartialClass2.cshtml

 <body> ... <div class="class1"> <p></p><a href="~/Files/2_кл_Формы для внес. результатов.xlsx">Формы для внесения результатов</a></p> @using (Html.BeginForm("Upload", "Work201615", FormMethod.Post, new { enctype = "multipart/form-data" })) { <input type="file" name="upload" /><br> <input type="submit" value="Загрузить" /> } </div> </body> 

enter image description here

Work201615Controller.cs

 [HttpPost] public ActionResult Upload(HttpPostedFileBase upload) { if(upload!=null) { //получаем расширение файла string fileExten = System.IO.Path.GetExtension(upload.FileName); //сохраняем файл в папку Files в проекте upload.SaveAs(@"\\192.168.88.220\файлы_пто\" + User.Identity.Name + fileExten); } return new RedirectResult(Url.Action("Select") + "#tab_1_2"); //Это не помогает } 

It is necessary that after uploading a file, a rending to the same tab takes place.

I tried using return new RedirectResult(Url.Action("Select") + "#tab_1_2"); but it gave nothing.

    1 answer 1

    How it works for me:

    Representation:

     <ul class="nav nav-tabs" id="myTabs"> <li>@Ajax.ActionLink("Программы", "GetProgramList", "Operations", new { operationId = Model.Id }, new AjaxOptions { UpdateTargetId = "Tabs" }, new { @data_target = "#Tabs", @data_toggle = "tab" } )</li> <li>@Ajax.ActionLink("Файлы", "GetAttachmentList", "Operations", new { operationId = Model.Id }, new AjaxOptions { UpdateTargetId = "Tabs" }, new { @data_target="#Tabs", @data_toggle = "tab" } )</li> </ul> <div id="Tabs"></div> 

    Javascript:

     $(function () { $('#myTabs a').click(function (e) { e.preventDefault(); $(this).tab('show') }); var lastTab = localStorage.getItem('lastTab'); // load content with ajax before show selected tab $('a[data-toggle="tab"]').on('show.bs.tab', function (e) { var url = $(this).attr('href'); var target = $(this).data('target'); $.ajax({ url: url, success: function (result) { $(target).html(result); } }) }) // for bootstrap 3 use 'shown.bs.tab', for bootstrap 2 use 'shown' in the next line $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { // save the latest tab; use cookies if you like 'em better: localStorage.setItem('lastTab', $(this).attr('href')); }); // go to the latest tab, if it exists: if (lastTab) { $('[href="' + lastTab + '"]').tab('show'); } else { lastTab = $('#myTabs a:first').attr('href'); $('[href="' + lastTab + '"]').tab('show'); } }); 

    When choosing any tab, I remember it in localStorage , when reloading the page I check the presence of the saved tab, if there is one, then I load the necessary content using ajax .

    Based on the decision from here