Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 动态渲染或渲染部分_Asp.net Mvc_Asp.net Mvc Partialview_Renderaction_Html.renderpartial - Fatal编程技术网

Asp.net mvc 动态渲染或渲染部分

Asp.net mvc 动态渲染或渲染部分,asp.net-mvc,asp.net-mvc-partialview,renderaction,html.renderpartial,Asp.net Mvc,Asp.net Mvc Partialview,Renderaction,Html.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.da

我有以下代码的视图:

    @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方法。 这将调用helper方法,该方法返回要调用以获取partialview的操作的名称

我似乎无法让它工作。
我遗漏了什么?

好的,我的一位同事找到了解决办法

解决方案在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.
}

对于PartialView,我们没有单独的js文件。

您能把它缩短为您看到的行为的最小示例吗?这是一个相当大的代码转储。我缩短了代码。我得到的错误是,我的模型ComPost.Core.commandQueries.Contract.DataContract.DepostDetaildTo没有方法RenderAction。我尝试了以下行:@{Html.RenderPartialDepositDetailOverview,new{id=@model.id};},但随后我得到消息:传入字典的模型项的类型为“f_u匿名类型0`1[System.Int32]”,但是这个字典需要一个类型为“ComPost.Core.CommandsAndQueries.Contract.DataContract.DepositorViewScreendTo”的模型项。我这样试过:@Html.RenderActionnew{Action=DepositorDetailOverview,Controller=Deposit},new{id=@model.id}但随后我得到消息:“System.Web.Mvc.HtmlHelper”不包含“RenderAction”的定义,最好的扩展方法重载“System.Web.Mvc.Html.ChildActionExtensions.RenderActionSystem.Web.Mvc.HtmlHelper,string,object”有一些无效的参数下一步我尝试如下:@Html.renderActionDepositionDetailOverview,new{id=@Model.id}并且我得到了与“System.Web.WebPages.WebPages.WebPageExecutingBase.WriteSystem.Web.WebPages.HelperResult”匹配的最佳重载方法具有一些无效参数