use*_*329 1 asp.net-mvc-4 rotativa
我正在使用 MVC 4 创建应用程序。我正在使用 Rotativa 创建 pdf。我正在使用复杂模型调用 ActionAsPdf
我的模型是
public class BrandingDetails
{
public int PDFFileNo { get; set; }
public string LogoImageUrl { get; set; }
public string WebsiteUrl { get; set; }
public string PhoneNumber_AU { get; set; }
public string PhoneNumber_NZ { get; set; }
public string FacebookImageUrl { get; set; }
public string TwitterImageUrl { get; set; }
public string PinterestImageUrl { get; set; }
public string YoutubeImageUrl { get; set; }
public string CruiseCode { get; set; }
public string ShipName { get; set; }
public string PortName { get; set; }
public string SailDate { get; set; }
public string CruiseNights { get; set; }
public string Destinations { get; set; }
public string QuoteRef { get; set; }
public string CruiseName { get; set; }
public string DescriptionCruise { get; set; }
public IEnumerable<CruiseOptions> CruiseOptions { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我正在调用以下内容
var viewModel = QuoteHelper.GetViewModel(item);
var pdfResult = new ActionAsPdf("CruiseDetails", quoteDetails, cruiseOptions);
var binary = pdfResult.BuildPdf(this.ControllerContext);
Run Code Online (Sandbox Code Playgroud)
它调用的我的 Action 方法是
public ActionResult CruiseDetails(BrandingDetails quoteDetails, IEnumerable<CruiseOptions> cruiseOptions)
{
return View("CruiseDetails", quoteDetails);
}
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,当我将其传递给操作时,所有数据都会传递给 CruiseOptions .. 没有设置为任何元素...这怎么可能?
太晚了,但根据 Josh 的回答,我找到了使用 JSON 的解决方案。我希望这对某人有帮助。
public class SalesReportModel : BaseModel
{
public List<Guid> UserGuids { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
public ActionResult GenerateSalesReport(string json)
{
SalesReportModel model = new JavaScriptSerializer().Deserialize<SalesReportModel>(json);
return View("SalesReport", model);
}
public ActionResult SalesReport(SalesReportModel model)
{
var json = new JavaScriptSerializer().Serialize(model);
return new Rotativa.ActionAsPdf("GenerateSalesReport", new { json = json });
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3776 次 |
| 最近记录: |