4

umbraco を使用してワークフローを作成しました。私がやろうとしているのは、かみそりテンプレート ( umbraco.forms) によって作成された html を取得するワークフローを作成することです。

のテンプレートがある場所は次のとおりですumbraco.forms

Views\Partials\Forms\Emails このテンプレートは、このワークフローが呼び出されたときにメールで送信したいものです。

public class SendMail : WorkflowType
{  
    //Here I get the path where the razor template is
    [Umbraco.Forms.Core.Attributes.Setting("Path to template",
     Description = "Path to template",
     View = "TextField")]
     public string Template{ get; set; }
   public SendMail()
   {

    this.Id = new Guid("ccbeb0d5-adaa-4729-8b4c-4bb439dc0204");
    this.Name = "Send Mail";
    this.Description = "Send Mail";
    this.Icon = "icon-plugin";
    this.Group = "Services";
   }
    //When workflow get called this method is executed 
    public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
   {

      //here I'm trying to get the template converted to string however isn't work
     //  string template = html.Raw(Template).ToString();
   }

}

試しstring template = html.Raw(Template);ましたが、アクセスできませんhtml.Raw("");

私はこのrecord.ParseWithRazorView(filePath);解決策を試しましたが、存在しないようです

近いことを行うワークフローがありますが、このコードを書き直したりアクセスしたりすることはできないようです

ここに画像の説明を入力

私のふりを正確に理解していない場合は、コメントしてください。すべての詳細で質問を更新します

4

6 に答える 6

1

このメソッドを作成します:

public string RenderRazorToString(string viewName, object model, ViewDataDictionary viewData = null)
{
    ViewData.Model = model;

    if (viewData != null)
        foreach (KeyValuePair<string, object> item in viewData)
            ViewData.Add(item);

    using (var sw = new System.IO.StringWriter())
    {
        var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
        var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
        viewResult.View.Render(viewContext, sw);
        viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
        return sw.GetStringBuilder().ToString();
    }
}

かみそりのテンプレートの文字列エクスポートが必要なすべての場所で呼び出します。

viewName は、テンプレート名です。model は、テンプレートで必要な場合のデータです。

于 2019-09-11T07:00:19.420 に答える