2014-02-28 263 views
0

目前我有一种将PDF加载到HTML页面的方法。 PDF是从数据库中检索数据后动态创建的。现在,我想要做的是在加载PDF视图之前,我想显示一个让用户知道信息正在加载的页面。将数据从控制器传递到视图并返回到控制器

ActionParams:

@using (Html.BeginForm("PreLoaderView", "Report", FormMethod.Post, new { 
    @target = "_blank" 
})) 

控制器:

public ActionResult PreLoaderView(TestViewModel viewModel) { 
    return View(viewModel); 
} 

public ActionResult SolicitorActionReport_Load(TestViewModel viewModel) { 
    var cultivationModel = new CultivationModel(viewModel, ConstituentRepository, CampaignRepository); 
    var cultivationData = cultivationModel.GetCultivationActivityData(); 
    var reportParamModel = new List<ReportParamModel> 
            { 
             new ReportParamModel() {AgencyName = SelectedUserAgency.AgencyName, StartDate = viewModel.StartDate, EndDate = viewModel.EndDate} 
            }; 
    return FileContentPdf("Constituent", "CultivationActivityManagement", cultivationData, reportParamModel, new List<FundraisingAppealMassSummary>(), new List<FundraisingAppealPortfolioSummary>()); 
    return Content(viewModel.SolicitorType); 
} 

PreLoaderView:

@model Report.SolicitorActionParamsViewModel 

@{ 
    ViewBag.Title = "Cultivation Activity"; 
} 
<script type="text/javascript"> 
    $(function() { 
     $.ajax({ 
      url: '@Url.Action("SolicitorActionReport_Load", "Report", @Model)', 

      complete: function() { 
       $('#progress').hide(); 
      }, 
      error: function() { 
       alert('oops'); 
      } 
    }); 
    }); 
</script> 

<div align="center"> 
    <img id="progress" src="~/Content/images/loading.GIF"> 
    <div id="result"> 
     <embed width="100%" height="800px" src="http://localhost/YP/Report/SolicitorActionReport_Load"type="application/pdf"> 
    </div> 
</div> 

所以,从PreLoaderView,我想通过@Model回控制器与SolicitorActionReport_Load()一起使用。这可能吗?

回答

0

这是要序列模型为Javascript什么,因此它可以被传递给Ajax调用:

<script type="text/javascript"> 
    $(function() { 
     $.ajax({ 
      url: '@Url.Action("SolicitorActionReport_Load", "Report", 
         @Html.Raw(new JavaScriptSerializer().Serialize(Model)))', 

      complete: function() { 
       $('#progress').hide(); 
      }, 
      error: function() { 
       alert('oops'); 
      } 
     }); 
    }); 
</script> 
0

你不应该做的是,在一个经典的MVC应用程序。您应该在控制器中创建并填写模型,然后将其一次馈送到视图中,然后将其忘记,直到下一次到服务器的往返。你不应该把它抛在控制器上。

你要做的事情应该是由客户端的iframe或后续的ajax调用完成。

相关问题