1

I가 다음과 같은 코드가이보기 :RenderAction 또는 RenderPartial 동적으로

@model ComPost.Core.CommandsAndQueries.Contract.DataContract.DepositDetailDTO 

@section scripts 
{ 
    <script src="~/Scripts/DataTables-1.9.4/media/js/jquery.dataTables.js"></script> 
    <script src="~/Scripts/jquery.datatables.bootstrap-pagination.js"></script> 
    <script src="~/js/DepositDetail.js"></script> 
} 

    @Html.RenderAction(new { Action = "DepositDetailOverview", Controller = "Deposit" }, new { id = @Model.Id }) 

내 컨트롤러는 다음과 같은 코드를했다 : 우리는 DepositDetail 화면에 갈 때

 public ActionResult DepositDetail(int id, int tabIndex = -1) 
    { 
     ViewBag.DepositId = id; 
     ViewBag.ActionMethodForPartialView = this.GetControllerActionForTabIndex(tabIndex); 
     DepositDetailDTO depositDetailDTO = this.QueriesServiceAgent.Call(s => s.GetDepositDetailForId(id)); 
     return View(depositDetailDTO); 
    } 

    public PartialViewResult DepositDetailOverview(int id) 
    { 
     ViewBag.DepositId = id; 
     DepositOverviewScreenDTO depositOverviewScreenDTO = this.QueriesServiceAgent.Call(s => s.GetDepositOverviewForId(id)); 
     return PartialView(depositOverviewScreenDTO); 
    } 

    private string GetControllerActionForTabIndex(int tabIndex) 
    { 
     if (tabIndex <= 0) 
     { 
      return "DepositDetailOverview"; 
     } 
     else if (tabIndex == 1) 
     { 
      return "DepositMailingLists"; 
     } 
     return "DepositFinalize"; 
    } 

, 우리가 전화를 "DepositDetail"- 컨트롤러의 방법. 부분 뷰를 가져 오기 위해 호출 할 작업의 이름을 반환하는 helper-method를 호출합니다.

나는 제대로 작동하지 않는 것 같습니다. 내가 무엇이 누락 되었습니까?

+0

보고있는 동작의 최소한의 예를 줄여 주시겠습니까? 이것은 꽤 큰 코드 덤프입니다. – jpmc26

+0

코드를 짧게했습니다. 내 모델 ComPost.Core.CommandsAndQueries.Contract.DataContract.DepositDetailDTO에 "RenderAction"메서드가 없다는 오류가 발생합니다. –

+0

나는이 줄을 시도했다 : @ {Html.RenderPartial ("DepositDetailOverview", new {id = @ Model.Id}); } 그러나 다음 메시지가 나타납니다. 사전에 전달 된 모델 항목의 형식은 '<> f__AnonymousType0'1 [System.Int32]'이지만이 사전에는 'ComPost.Core.CommandsAndQueries.Contract.DataContract'유형의 모델 항목이 필요합니다. .DepositOverviewScreenDTO '. –

답변

0

OK, 제 동료가 해결책을 찾았습니다.

해결 방법은 js 파일에 있습니다. 다음과 같이이 보일 것입니다 :

$(document).ready(function() { 

    // Upon every page refresh, the tab with the current tab index is highlighted 
    var currentTabIndex = $('#MainTabs').data("tabindex"); 
    $('#MainTabs li:eq('+ currentTabIndex +') a').tab('show'); 

    if (currentTabIndex == 1) { 
     loadMailingListsForDepositTable(); 
    } 
    if (currentTabIndex == 2) { 
     LoadFinalizeInformation(); 
    } 

    // wire up the tab clicked event, which requests a full page reload on the new tab index 
    $('#MainTabs').click(function (e) { 
     e.preventDefault(); 
     var nextTabIndex = $('#MainTabs li a:active').data('index'); 
     var depositId = $("#MainTabs").data("depositid"); 
     var dataSourceUrl = $("#MainTabs").data("datasourceurl").replace("-1", depositId).replace("-2", nextTabIndex); 
     document.location.href = dataSourceUrl; 
    }); 

}); 

var LoadFinalizeInformation = function() { 
    document.getElementById('OverrideCheckox').onchange = function() { 
     document.getElementById('OverrideReason').disabled = !this.checked; 
     document.getElementById('DepositProductSelect').disabled = !this.checked; 
    }; 
} 

var loadMailingListsForDepositTable = function() { 
    // do other stuff here. 
} 

을 그리고 partialviews 위해 우리는 별도의 js 파일이 없습니다.