.net - 通过 Razor 创建新节点(在 Umbraco 中)

标签 .net razor umbraco

我正在尝试在 Umbraco 内创建一个预订系统,以便在我的网站上提交预订表单后,它还会在 Umbraco 后端创建一个新节点以供引用。仅使用 Razor 可以做到这一点吗?如果没有,我怎样才能创建这个功能?

我目前正在使用 Umbraco 文档中向我建议的以下代码(通过将其添加到发送成功时运行的代码块中),但我的 razor 脚本出现错误:

using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;

DocumentType dt = DocumentType.GetByAlias("Textpage"); 
User author = User.GetUser(0); 
Document doc = Document.MakeNew("My new document", dt, author, 1018); 

我正在使用 Umbraco v4.7.1.1 并收到以下错误:“找不到类型或命名空间名称“DocumentType”(是否缺少 using 指令或程序集引用?)”。

如果我将 @ 添加到命名空间,则会收到错误:“System.Security.Principal.IPrincipal”不包含“GetUser”的定义,并且没有扩展方法“GetUser”接受类型为“System”的第一个参数可以找到 .Security.Principal.IPrincipal'(您是否缺少 using 指令或程序集引用?)

最佳答案

using 语句需要位于 razor 代码块之外:

@using umbraco.BusinessLogic;
@using umbraco.cms.businesslogic.web;
@{
    DocumentType dt = DocumentType.GetByAlias("Textpage"); 
    User author = User.GetUser(0); 
    Document doc = Document.MakeNew("My new document", dt, author, 1018); 
}

关于.net - 通过 Razor 创建新节点(在 Umbraco 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10580096/

相关文章:

c# - 使用 Razor 引擎的 ASP.NET MVC 3 中的 '/' 应用程序中的服务器错误

asp.net - 在 Webforms 项目中使用 Umbraco v7.2.1 网格布局

c# - 我想将 Umbraco 4.11.6 升级到 4.11.9

.net - 无法加载文件或程序集 'AssemblyName PublicKeyToken=null' 或其依赖项之一

c# - 单元测试是否捕获到异常

.net - 在 IDisposable 的 Quartz .NET IJob 中调用 Dispose() 的正确方法是什么?

c# - MVC Razor,包含来自另一个项目的 JS/CSS 文件

c# - 根据所选语言更改 Controller 和操作名称

.net - 未应用 AllowAnonymous 属性, Controller 操作仍需要登录

c# - 错误 : Must create DependencySource on same Thread as the DependencyObject even by using Dispatcher