0

我正在尝试创建包含一个

  1. 可编辑的 cshtml 视图页面

接着

  1. 单击按钮后,将编辑后的内容保存为 PDF

所以这是整个cshtml视图页面,

        @model IEnumerable<int>

        @{
            ViewBag.Title = "Create Template";
        }
        <!DOCTYPE html>
        <html>
        <head>
            <title>Create a Template</title>
        </head>
        <body>
                    <div id='template'>
                       <h1 contentEditable='True'>Product Name</h1>
                        <div >
                          <h2 contentEditable='True'>Product Description</h2>       
                          <p contentEditable='True'>London is the capital city of England.</p>
                       </div>
                   </div>

          <button id="btn_sumbit" type="button" class="btn btn-danger submit">Save as PDF</button>

        </body>
        </html>

        @section Scripts {

            @Scripts.Render("~/bundles/jqueryval")
            @Scripts.Render("~/bundles/jqueryui")

            <script type="text/javascript">

                $('#btn_sumbit').on('click', function () {

                    var div_value = document.getElementById('template').innerHTML;

                    RazorPDF.PdfResult(div_value, "PDF");
                });

            </script>

        }

我正在使用RazorPDF来执行此任务,但是一旦单击此按钮,它就不会保存为 PDF

我可以编辑这个 cshtml 视图页面,我想将最终编辑的内容保存为 pdf(这是动态视图)

4

1 回答 1

1

我认为你做错了。“RazorPDF.PdfResult(...)”行属于控制器而不是视图。

观看此视频:http : //nyveldt.com/blog/post/Introducing-RazorPDF 它应该让您更清楚地了解 RazorPDF 中的工作原理。

编辑:

只需创建一个控制器方法,它会根据参数生成一个 PDF 视图。

public ActionResult Pdf(string name, string description) {
    var product = new Product();
    product.Name = name;
    product.Description = description;

    var pdfResult = new PdfResult(product, "Pdf");

    return pdfResult;
}

当然,您需要创建一个包含信息的 Product-Class。

在您的 Javascript 部分中,您可以编写:

location.href = @Url.Action("Pdf", "Controllername") + "?name=" + name + "&description=" + description;

这有望生成一个您可以在 Javascript 中关注的链接。name 和 description 是保存用户输入信息的 Javascript 变量。

你明白吗?我的方法是根据可编辑视图的信息在不同的视图(如该视频中)生成 PDF 内容。

告诉我它是否有效。;-)

于 2015-11-02T10:37:35.743 回答