3

上の例を使用しhttp://weblog.west-wind.com/posts/2012/May/30/Rendering-ASPNET-MVC-Views-to-Stringて VIEW を文字列として渡し、電子メールとして送信しようとしています。販売の請求書を電子メールでユーザーに送信する必要があります。

プロジェクトに ViewRenderer クラスを追加しました。次に、ContactSeller 関数をコントローラーに追加し、請求書ビューをコピーして名前を次のように変更しました。ViewOrderThroughEmail.cshtml

  [HttpPost]
    [AlwaysAccessible]
    public ActionResult SendEmailAttachment(QBCustomerRecord cust)
    {
        ContactSellerViewModel model = new ContactSellerViewModel();
        string invoiceEmailAsString = ContactSeller(model);
        _userService.SendEmail(username, nonce => Url.MakeAbsolute(Url.Action("LostPassword", "Account", new { Area = "Orchard.Users", nonce = nonce }), siteUrl), invoiceEmailAsString);

        _orchardServices.Notifier.Information(T("The user will receive a confirmation link through email."));

        return RedirectToAction("LogOn");
    }

    [HttpPost]
    public string ContactSeller(ContactSellerViewModel model)
    {   
        string message = ViewRenderer.RenderView("~/Orchard.Web/Modules/RainBow/Views/Account/ViewOrderThroughEmail.cshtml",model,
                                                     ControllerContext);     
        model.EntryId = 101;
        model.EntryTitle = message;


        return message;
    }

しかし、これはエラーをスローします.VIEWはNULLにできません:

  using (var sw = new StringWriter())
    {
        var ctx = new ViewContext(Context, view,
                                    Context.Controller.ViewData,
                                    Context.Controller.TempData,
                                    sw);
        view.Render(ctx, sw);
        result = sw.ToString();
    }

RenderViewToStringInternalViewRenderer.csの関数で。私はそれがビューのパスだと思っていましたが、そうではありませんでした。

何か案は?ありがとう

4

1 に答える 1