简体   繁体   English

MVC和Ajax.BeginForm和DIV.Load

[英]MVC And Ajax.BeginForm and DIV.Load

I have a partial that defines an Ajax.BeginForm. 我有一个部分,它定义了一个Ajax.BeginForm。 The model returned has a property for ReportLink created on the server resource that returns a Url to a PartialView. 返回的模型具有在服务器资源上创建的ReportLink的属性,该属性将Url返回给PartialView。

On the Ajax,BeginForm.OnSuccessFunction I am attempting to return and load html content with $("reportContent").load(AJAXRESULT.RenderLink) 在Ajax上,BeginForm.OnSuccessFunction我正在尝试使用$("reportContent").load(AJAXRESULT.RenderLink)返回并加载html内容$("reportContent").load(AJAXRESULT.RenderLink)

However, I get into an infinite loop somewhere. 但是,我在某个地方陷入了无限循环。

Edited to add moving parts: 编辑添加运动部件:

@model xxxx.Reports.Models.Reports.BaseReportModel
@{Layout = null;}
<div id="reportBase" class="k-content">
<div id="reportControl" >  
@using (Ajax.BeginForm(
          Model.PostAction,          
          Model.PostController,
          null,
          new AjaxOptions() { OnSuccess = "editPostSuccess", OnFailure = "editPostFailure" },
          new { id = "reportBase_frmViewer", name = "reportBase_frmViewer" }))
        {    
            @Html.AntiForgeryToken()            
            @RenderSection("reportParams", required: false)  
            if (@Model.AllowRefresh){
                <input type="button" id="btnRefresh" value="refresh" />
            }
            if (@Model.AllowExportToPDF){
                <input type="button" id="btnPDF" value="PDF" />
            }
            if (@Model.AllowExportToExcel){
                <input type="button" id="btnExcel" value="XLS" />
            }  
            @Html.HiddenFor(p => p.AllowExportToExcel)   
            @Html.HiddenFor(p => p.AllowExportToPDF)
            @Html.HiddenFor(p => p.AllowRefresh)      
            @Html.HiddenFor(p => p.AutoStartReport)   
        }   
    </div>
</div>
<div id="wait"></div>
<div id="reportContent"></div>
//The 
<script type="text/javascript">

    function editPostSuccess(ajaxContext) {
        showWaitIndicator(false);       
        $('#reportContent').load(ajaxContext.RenderLink**,<--This is a link to an asction that calls renderPartial on the controller** function () {
            $("#reportContent").show();
        });
    }

    function editPostFailure(ajaxContext) {
        showWaitIndicator(false);
        var response = JSON.parse(ajaxContext.responseText);
        var errorMessage = response.Message;
        $('#reportContent').html('@Resources.labels.lblServerErrorsOnForm' + " " + errorMessage);
        $("#reportContent").show();
        alert("FAILURE:"+response.Message);
    }

Update: I am no longer sure that browser is locking up. 更新:我不再确定浏览器是否锁定。 The content is 3.15 MB. 内容是3.15 MB。 I think the raw html is very verbose and takes that long to render in the browser. 我认为原始html非常冗长,需要花费很长时间才能在浏览器中呈现。 Here is the execution sequence: 这是执行顺序:

  1. LoadPartial(ReportModel) - This has an Ajax.BeginForm() that returns report meta data and has a refresh button. LoadPartial(ReportModel)-它具有一个Ajax.BeginForm(),它返回报表元数据并具有一个刷新按钮。 When the refresh button is clicked. 单击刷新按钮时。 I call a js function that loads a div using div.load(ReportModel.RenderLink), which is a url to get the content as html from the controller. 我调用了一个js函数,该函数使用div.load(ReportModel.RenderLink)加载div,这是一个从控制器以html格式获取内容的URL。

  2. The ReportModel.RenderLink points to a controller method that returns an html report based on model params sent to the controller. ReportModel.RenderLink指向控制器方法,该方法基于发送到控制器的模型参数返回html报告。 The result is a PartialView("ReportContentPartial",string) where string is the html fragment. 结果是PartialView(“ ReportContentPartial”,string),其中string是html片段。

  3. For testing the ReportContentPartial just dumps @Model into a div as @Html.Raw(Model) and this is where the browser locks up. 为了测试ReportContentPartial,只需将@Model转储为div作为@ Html.Raw(Model),这就是浏览器锁定的地方。 I thought it was in an infinite loop but it is just taking way to long to render the html. 我以为它处于无限循环中,但是渲染html的时间很长。

The part I do not understand is when I use @Html.BeginForm and dump the @Html.Raw(HTML) it is pretty quick. 我不了解的部分是当我使用@ Html.BeginForm并转储@ Html.Raw(HTML)时,它非常快。 I need to somehow use the same mechanism used in that rendering method. 我需要以某种方式使用该渲染方法中使用的相同机制。 The report html is fetched and returned in less than a second. 报告html会在不到一秒钟的时间内获取并返回。 The problem is when I trace out of @Html.Raw(HTML) the browser locks and takes +15 seconds to render the content. 问题是当我退出@ Html.Raw(HTML)时,浏览器锁定并花费+15秒来呈现内容。

I will keep plugging at it. 我会继续堵住它。 I am sure there is a more efficient way to go about it and I probably need to think about ways to break up the reports. 我确信有一种更有效的解决方法,我可能需要考虑分解报告的方法。

Update 2: This seems to be development environment issue. 更新2:这似乎是开发环境问题。 I am launching IE from VS2012 using the run command. 我正在使用run命令从VS2012启动IE。 I sense that something is up with the asp.net dev server. 我感觉到asp.net开发服务器出现了问题。 When I load the same url in chrome, while debugging in vs, it renders in less than a second. 当我在chrome中加载相同的url时,在vs中进行调试时,渲染时间不到一秒钟。

I solved this. 我解决了 It seems there was an issue with browser definition files that shipped with .net 40. I resorted back to a forms based version of the reporting application that used .aspx pages and postbacks to see why it would render fast and the MVC version was so slow. 似乎.net 40附带的浏览器定义文件存在问题。我求助于使用.aspx页和回发的报表应用程序的基于表单的版本,以查看为什么它呈现速度快而MVC版本太慢。 When using IE 10 it would not render and I found the _dsoPostBacks were not working on the forms version. 使用IE 10时,它将无法呈现,并且我发现_dsoPostBacks在表单版本上不起作用。 I then found Scott Hanselman's blog on browsers definition files and applied the hotfix on the test server and now the mvc version in ie is rendering at an acceptable rate. 然后,我在浏览器定义文件上找到了Scott Hanselman的博客 ,并在测试服务器上应用了此修补程序,现在其中的mvc版本以可接受的速率呈现。 It has something to do with recognizing the browser and downgrading js support. 它与识别浏览器和降级js支持有关。 I do not know why that fixed my problem but it did :) 我不知道为什么这解决了我的问题,但确实做到了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM