如何将复杂模型传递给ActionAsPDF?

时间:2013-12-17 06:07:52

标签: asp.net-mvc-4 rotativa

我正在创建一个MVC 4应用程序。我正在使用Rotativa生成pdfs

他们有一个名为

的方法
public ActionAsPdf(string action, object routeValues);

我无法将复杂对象传递给routeValues

即:

我有一个viewModel

public class FullName
{
    public string FirstName { get; set; }
    public string Surname { get; set; }
}

public ActionResult Index(FullName name)
{
    ViewBag.Message = string.Format("Hello {0} to ASP.NET MVC!", name);
    return View();
}

public ActionResult Test()
{
    var fullname = new FullName();
    fullname.FirstName = "John";
    fullname.Surname = "Smith";

    return new ActionAsPdf("Index", new { name = fullname }) { FileName = "Test.pdf" };
}

当我单步执行时,在Index操作中,名称为空...如何通过复杂模型?

2 个答案:

答案 0 :(得分:4)

检查

return new ActionAsPdf("Index", fullname ) { FileName = "Test.pdf" };

答案 1 :(得分:1)

public ActionResult viewForPDFFile(int id)
{
    Data data = new Manager().GetData(id);
    return View(data); // this view content will show in PDF File
}

然后简单地称之为

return new ActionAsPdf("viewForPDFFile", new { id = id} ) { FileName = String.Format("File_{0}.pdf",id) };