1

У меня есть такая точка зрения, что имеет следующий код: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 }) 

Мой контроллер имеет следующий код:

 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-экран, мы называем Метод «DepositDetail» на контроллере. Это вызов вспомогательного метода, который возвращает имя вызываемого действия для получения частичного просмотра.

Я не могу заставить его работать. Что мне не хватает?

+0

Не могли бы вы сократить это до минимального примера поведения, которое вы видите? Это довольно большой дамп кода. – jpmc26

+0

Я сократил код. Я получаю ошибку, что моя модель ComPost.Core.CommandsAndQueries.Contract.DataContract.DepositDetailDTO не имеет метода «RenderAction». –

+0

Я пробовал эту строку: @ {Html.RenderPartial ("DepositDetailOverview", новый {id = @ Model.Id}); } Но потом я получил сообщение: Элемент модели, переданный в словарь, имеет тип «<> f__AnonymousType0'1 [System.Int32]», но для этого словаря требуется элемент модели типа «ComPost.Core.CommandsAndQueries.Contract.DataContract .DepositOverviewScreenDTO. –

ответ

0

ОК, мой коллега нашел решение.

Решение было в 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-файла.

Смежные вопросы