1

I have this view that has the following code:

    @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 })

My controller has the following code :

        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";
    }

When we go to the DepositDetail-screen, we call the "DepositDetail"-method on the controller. This calls the helper-method which returns the name of the action to be called to get the partialview.

I can't seem to get it working. What am I missing?

tereško
  • 58,060
  • 25
  • 98
  • 150
Bart Schelkens
  • 1,235
  • 4
  • 21
  • 45
  • Could you shorten this to a minimal example of the behavior you're seeing? This is a pretty big code dump. – jpmc26 Sep 19 '14 at 06:02
  • I shortened the code. I get the error that my model ComPost.Core.CommandsAndQueries.Contract.DataContract.DepositDetailDTO doesn't have a method "RenderAction". – Bart Schelkens Sep 19 '14 at 06:07
  • I tried this line :@{ Html.RenderPartial("DepositDetailOverview", new { id = @Model.Id }); } But then I got the message : The model item passed into the dictionary is of type '<>f__AnonymousType0`1[System.Int32]', but this dictionary requires a model item of type 'ComPost.Core.CommandsAndQueries.Contract.DataContract.DepositOverviewScreenDTO'. – Bart Schelkens Sep 19 '14 at 06:10
  • I tried it like this : @Html.RenderAction(new { Action = "DepositDetailOverview", Controller = "Deposit" }, new { id = @Model.Id }) but then I get the message : 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderAction' and the best extension method overload 'System.Web.Mvc.Html.ChildActionExtensions.RenderAction(System.Web.Mvc.HtmlHelper, string, object)' has some invalid arguments – Bart Schelkens Sep 19 '14 at 06:11
  • Next I tried it like this : @Html.RenderAction("DepositDetailOverview", new { id = @Model.Id }) and i got The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments – Bart Schelkens Sep 19 '14 at 06:13

1 Answers1

0

OK, a colleague of mine found the solution.

The solution was in the js-file. This should look as follows :

    $(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.
}

And for the partialviews we don't have a separate js-file.

Bart Schelkens
  • 1,235
  • 4
  • 21
  • 45