上传文档并在XForm中发送

时间:2014-02-26 09:27:51

标签: upload content-management-system document episerver

我正在使用 EPiServer CMS 7.5 MVC应用程序。

我只能在创建新表单时看到文本框和按钮。我希望在点击时有一个上传文档的链接。然后,此文档应该能够在查看表单数据时查看,并且还应该与邮件一起附加。

任何帮助?

1 个答案:

答案 0 :(得分:1)

XForm编辑器中没有文件上传控件。一个选项 - 修改XForm的呈现方式。 EPiServer中的XForm使用显示模板进行渲染。添加文件上载的一种方法是创建自己的XForm显示模板并添加文件上载。显示模板将用于应用程序中的所有XForms。

要创建显示模板,请在Visual Studio中的/ Views / Shared / DisplayTemplates /下创建XForm.cshtml。以下是XForm.cshtml的源代码示例:

@using EPiServer.HtmlParsing
@using EPiServer.Web.Mvc.Html
@model EPiServer.XForms.XForm

@if (ViewData["XFormActionResult"] is EPiServer.Web.Mvc.XForms.XFormSuccessActionResult)
{
    <strong>Form posted.</strong>
}
else
{
    using (Html.BeginXForm(Model, new { @class = "form xform" }))
    {
        if (Model != null)
        {
            foreach (HtmlFragment fragment in (IEnumerable<HtmlFragment>)ViewData["XFormFragments"] ?? Model.CreateHtmlFragments())
            {
                // here can override particular fragment
                // for example, check if TextBox Css class is "file-upload"
                // then replace it with file upload
                @Html.Fragment(fragment)
            }
        }
    }
}

之后你必须自己处理发布表格。本文将详细介绍如何执行此操作:http://www.eyecatch.no/blog/2013/01/using-xforms-and-mvc-in-an-episerver-7-block/

然后在BasePageController中的OnActionExecuting上,您可以处理文件上传。您可以将它存储在blob(在EPi 7 VPP中)并在XForm中存储引用(GUID)。