如何创建Razor视图以捕获Umbraco中的某种内容类型?

时间:2014-02-23 08:31:06

标签: razor content-management-system umbraco

我找到的所有文档都很多,它们展示了如何创建内容类型,使用Umbraco UI捕获该内容类型的文档,以及如何创建模板来显示该文档。

我确定我需要一个POST动作,它将获得一个反映内容类型结构的视图模型;它是变量和其他内容,但在哪里找到这个以及如何处理数据对我来说仍然是一个谜。

如何创建文档捕获视图以及如此常见的显示视图?

1 个答案:

答案 0 :(得分:1)

创建一个POST到表面控制器的表单相当容易。 Our Umbraco社区网站上有一个非常好的教程,可能对您有用。您可以找到教程here

在处理POST的控制器操作中,您需要添加对Umbraco Management API的调用,该调用用于CRUD操作。

以下是如何在Umbraco 6 +中创建和填充内容文档属性的示例:

private void AddProduct(int productId, string name, int productGroupId, int price)
    {
        // Get the Umbraco Content Service
        var contentService = Services.ContentService;

        var product = contentService.CreateContent(
            name,           // the name of the product document
            productGroupId, // the parent id should be the id of the group node 
            "product",      // the alias of the product Document Type
            0);

        // Here's how to update some of the properties
        product.SetValue("productId", productId);
        product.SetValue("originalName", name);
        product.SetValue("priceDKK", price);

        // finally we need to save and publish, this saves the product and the property values
        contentService.SaveAndPublish(product);
}

有类似的媒体,文件,数据类型等服务。有关详细信息,请查看Umbraco v6 + here和早期版本here